Extract Multiple Entries with XML
Posted: Wed Mar 17, 2010 11:40 am
Hi,
I recently posted this code in another thread to help someone, then I found myself intrigued as to how to access multiple entries within an XML file:
I'm wondering how can I print elements from <person id="n">? How do I specify?
Cheers
I recently posted this code in another thread to help someone, then I found myself intrigued as to how to access multiple entries within an XML file:
Code: Select all
<?php
//HEREDOC containing XML
$xmlAddressBook = <<<XML
<?xml version='1.0'?>
<addressbook>
<person id="1">
<name>John Smith</name>
<phone>01232458987</phone>
<address>20 Quiet Lane</address>
</person>
<person id="2">
<name>John Jackson</name>
<phone>01234458657</phone>
<address>20 Loud Lane</address>
</person>
</addressbook>
XML;
//Load XML heredoc into a variable using simplexml_load_string
$getXML = simplexml_load_string($xmlAddressBook);
print_r($getXML);Cheers