Hi everyone, I have been asked to help extract data from a xml file and use the data to input into html form designed in php

I have read a few articles but im missing the point some how...

On the file that im trying to get the data to I have the following at the top

//file name to get
$file = "hpi.xml"; 
//load xml file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

There are no errors so I assume the file is loading correctly

Here is the test xml file i have been provided with

<?xml version="1.0" ?> 
<HPICheck_Query VRM="A15TPH" VIN=""> 
<enquiry_number>000001</enquiry_number> 
<product_code>HPI11</product_code> 
<FirstReg> 
<Date>01/12/94</Date> 
<vin_vrm_indicator>1</vin_vrm_indicator> 
</FirstReg> 
<Basic> 
<Vrm>A15TPH</Vrm> 
<Fuel>Petrol</Fuel> 
<Transmission /> 
<Make> - <![CDATA[ MERCEDES]]> 
</Make> 
<Model> - <![CDATA[ 200 E 4V]]> 
</Model> 
<Engine_No>11194020001833</Engine_No> 
<DVLA_Body_Plan_Description>4 Door Saloon</DVLA_Body_Plan_Description> 
<SMMT_Door_Plan_Code /> 
<Engine_Size>01998</Engine_Size> 
<DVLA_Body_Plan_Code>02</DVLA_Body_Plan_Code> 
<Make_Code>M2</Make_Code> 
<fuel_code>1</fuel_code> 
<SMMT_Door_Plan_Description /> 
<Colour_Code>M</Colour_Code> 
<Door_Plan>4 Door Saloon</Door_Plan> 
<Colour>SILVER</Colour> 
<Model_Code>277</Model_Code> 
<transmission_code /> 
<Vin /> 
</Basic> 
<Additional> 
<Prev_Colour>RED</Prev_Colour> 
<Wheelplan>2 Axle Rigid Body</Wheelplan> 
<Wheelplan_code>C</Wheelplan_code> 
<Mfr_Year>1994</Mfr_Year> 
<Import_Flag>No</Import_Flag> 
<original_colour_code>M</original_colour_code> 
<Export_Date /> 
<Data_Source /> 
<number_of_previous_colours>02</number_of_previous_colours> 
<last_previous_colour_code /> 
<Weight>1234567</Weight> 
<original_colour_desc>SILVER</original_colour_desc> 
<Prev_Colour_Code>C</Prev_Colour_Code> 
<Scrap_Date /> 
<last_previous_colour_code_desc /> 
<Prev_Colour_Date>08/08/1999</Prev_Colour_Date> 
</Additional> 
<Keeper> 
<Keepers>000</Keepers> 
<previous_keeper_disposal_date /> 
<previous_keeper_acquisition_date /> 
<Kpr_Change /> 
</Keeper> 
<Summary> 
<Veh_Regd>Recorded</Veh_Regd> 
<Plate_Xfr>Not Recorded</Plate_Xfr> 
<Sec_Watch>0</Sec_Watch> 
<Stolen>0</Stolen> 
<Finance>0</Finance> 
<Cond_Damgd>0</Cond_Damgd> 
<Cond_Theft>0</Cond_Theft> 
<Cond_Hist>0</Cond_Hist> 
<VIN_Match>Not Matched</VIN_Match> 
<Session>01011613383459</Session> 
</Summary> 
<Misc_Data> 
<Date>Tue Jan 16 2001 13:39:34</Date> 
</Misc_Data> 
</HPICheck_Query>

What I am trying to do is extract the information from the above xml file and place into the form using php - like this

<tr>
    <td width="9">&nbsp;</td>
    <td width="142" valign="top"><div align="right" class="p"> <img src="img/arrow.png" width="16" height="16" hspace="2" vspace="2" align="right" />Make&nbsp;&nbsp;</div></td>
    <td width="346"><div class="ta">
      <input name="make" type="text" class="ta" id="make" size="35" maxlength="30" value="<?php echo $xml->Make; ?>" /><div class="smalltext">Make of vehical</div><?php echo $msg_title; ?></div></td>
    <td width="13">&nbsp;</td>
  </tr>

But for some reason, no data is being displayed in the textbox on the form -

Where is it that I am going wrong ! If someone could show me how to get the first 2-3 items from the xml, I will work through the rest, teaching myself as I go along

Many thanks for taking your time to read this post and any help would be appreciated

Seems i might be getting somewhere - I have found the following the prints only the top section of the xml file ?

<?php
$xml = simplexml_load_file("hpi.xml");

echo $xml->getName() . "<br />";

foreach($xml->children() as $child)
  {
  echo $child->getName() . ": " . $child . "<br />";
  }
?>

How can I get the information out of the xml file from the <basic> </basic>

I have tried changing getName to Basic but that gives me an error message

Hi everyone -

I now have the file looking like the following -
What i am trying to do is extract pieces of data from each section

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [VRM] => YP51PVJ
            [VIN] => WF0AXXGCDA1D40899
        )

    [Section_07] => SimpleXMLElement Object
        (
            [enquiry_number] => 000005
            [product_code] => HPI11
        )

    [FirstReg] => SimpleXMLElement Object
        (
            [Date] => 31/01/02
            [vin_vrm_indicator] => 1
        )

I have been trying to use the following that I found on the web, put I am unable to get the xml data into variables -

foreach ($xml->Section_07->result as $v) {
  $enquiry_number = $v->enquiry_number;
  $product_code = $v->product_code;
  
      	echo $v->enquiry_number;
    	echo $v->product_code;

Any help would be great

Hi, for those that are interested or require to generate php variables from xml -
the following works great. For me anyways

<?php foreach ($HpiCheck_Query->Basic->Engine_Size as $Engine_Size) { echo "$Engine_Size "; } ?>

Hope it helps someone in the future

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.