xpath node names

webmasterbeta

New Member
Hi

I'm experimenting with PHP/XML and XPath, I have some very simple code that returns the contents of nodes. What I cannot do is find the code that return the node names i.e British_Birds, species, name etc. I am using PHP 5.0.3 which supports xpath but I am getting a lot of undefined method errors. Does anyone know how I get the node names?

Code so far:-
<?php

$s = simplexml_load_file('birds5.xml');

foreach ($s->xpath('//species/name') as $species_name)
{
echo $species_name, '<br />';
}
?>

Returns:-
Golden oriole
Sparrowhawk
Siskin
Hoopoe

-------------------------------
birds5.xml
<British_Birds>

<species>
<name>Golden oriole</name>
<latin>Oriolus oriolus</latin>
<status>Summer</status>
<breeding>9-42</breeding>
<passage>85</passage>
<image>golden_oriole.jpg</image>
<url>http://www.rspb.org.uk/birds/guide/g/goldenoriole/index.asp</url>

</species>

</British_Birds>
 
Back
Top