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=""> 
<Transmission /> 
<Make> - <![CDATA[ MERCEDES]]> 
<Model> - <![CDATA[ 200 E 4V]]> 
<DVLA_Body_Plan_Description>4 Door Saloon</DVLA_Body_Plan_Description> 
<SMMT_Door_Plan_Code /> 
<SMMT_Door_Plan_Description /> 
<Door_Plan>4 Door Saloon</Door_Plan> 
<transmission_code /> 
<Vin /> 
<Wheelplan>2 Axle Rigid Body</Wheelplan> 
<Export_Date /> 
<Data_Source /> 
<last_previous_colour_code /> 
<Scrap_Date /> 
<last_previous_colour_code_desc /> 
<previous_keeper_disposal_date /> 
<previous_keeper_acquisition_date /> 
<Kpr_Change /> 
<Plate_Xfr>Not Recorded</Plate_Xfr> 
<VIN_Match>Not Matched</VIN_Match> 
<Date>Tue Jan 16 2001 13:39:34</Date> 

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

    <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>

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

6 Years
Discussion Span
Last Post by LloydFarrell

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

$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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.