Forum Moderators: coopster
usually I have a structure of
<person>
<name>Joe Bloggs</name>
<age>21</age>
</person>
<person>
<name>Sarah Bloggs</name>
<age>25</age>
</person>
Which I usually parse with a string like this:
foreach ($xml->xpath('//name') as $names) { I have another XML file which has a different format and takes the following format:
<Names>
<name>Joe Bloggs</name>
<age>21</age>
</Names>
<Names>
<name>Sarah Bloggs</name>
<age>25</age>
</Names>
The problem I've got is that because the top level is also contains the phrase names which I search for with XPath - the parsing doesn't work.
Any suggestions gratefully received
How about something like :-
[pre]$xml=<<<XML
<?xml version='1.0'?>
<doc>
<person>
<name>Joe Bloggs</name>
<age>21</age>
</person>
<person>
<name>Sarah Bloggs</name>
<age>25</age>
</person>
</doc>
XML;
$doc=new SimpleXMLElement($xml);
var_dump($doc->xpath('//person/name'));
[/pre]