Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use value in XML file

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i have a php page which i type a numberplate into, this is processed when the form is submitted and i get an xml page back.. How can i read a value from the xml and use it in my php page?

example xml....

<?xml version="1.0"?>
<HPICheck_Query VRM="abc123" VIN="xxx">
<enquiry_number>
00001
</enquiry_number>
</HPICheck_Query>

Kindest regards,

BF
 
If that's as complex as the XML gets then you could simply use Regular Expressions to grab the bit you need.

However, the "proper" way to do it would be to parse the XML file. There are a number of XML parsing classes around which should make this quite simple.

Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Hi, thanks for replying. Whats the best way to do this properly...

Can i have a php page to enter the nummberplate into, then another php loads (which submits the numberplate in a form and recieves the xml) then displays the value i want from the xml??

Hopfully you know what i mean!!

Many thanks,

Brian
 
Hi, if it helps this is some more info on what i am doing..

We have a webservice that we have subscribed to, when i enter our username, password, initials and numberplate into the address bar the xml results are opened in notepad.

I want to do this in php, and get certain values out of the xml and use them in my php pages!

Hope this helps,

Many thanks,

Brian
 
as pointed out, there are two ways. one uses parsing xml and the other regular expressions. there are probably others using programmatic search functions.

Code:
$xml =	<<<XML
<?xml version="1.0"?>
<HPICheck_Query VRM="abc123" VIN="xxx">
<enquiry_number>
00001
</enquiry_number>
</HPICheck_Query>
XML;

$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $vals, $index);
xml_parser_free($p);
$enquiryNumber = trim($vals[1]['value']);
$VRM = trim($vals[0]['attributes']['VRM']);
$VIN = trim($vals[0]['attributes']['VIN']);


Code:
$xml =	<<<XML
<?xml version="1.0"?>
<HPICheck_Query VRM="abc123" VIN="xxx">
<enquiry_number>
00001
</enquiry_number>
</HPICheck_Query>
XML;

$pattern = '/VRM="(.*?)"\s*VIN="(.*?)".*?enquiry_number>\s*(\d*)\s*/imsx';
$result = preg_match($pattern, $xml, $match);
if ($result){
	list($whole, $VRM, $VIN, $enquiryNumber) = $match;
} else {
 die ('invalid input');
}
 
Hi, thanks for your reply - looks like you know what im trying to do! I just need to get the KtypeNr value to use else where?

Could you show me an example of how to do this???

Kindest regards,

Brian
 
the Ktype number is not returned in the xml snippet you posted therefore you cannot obtain it using either method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top