PHP: get xml children without parent -


i load xml file simplexml_load_file

xml :

<list>    <top>       <test>          <id>1</id>       </test>       <test>          <id>2</id>       </test>       <test>          <id>3</id>       </test>    </top>    <test>        <id>4</id>    </test> </list> 

i want test tag one foreach

i dont use top parent test chilren

how can ?

you want test elements anywhere in xml? in case can use xpath somelike this

$xml = simplexml_load_file('xml.xml');  $testelements = $xml->xpath('//*/test'); // return array of test elements 

Comments