My Name
My Name

Reputation: 285

PHP: get xml children without parent

I load XML file by 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 get all TEST tag by one foreach

I dont use top parent for get test chilren

How i can ?

Upvotes: 0

Views: 49

Answers (1)

LiTe
LiTe

Reputation: 158

You want all TEST elements which are anywhere in XML? In that case you can use xpath somelike this

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

Upvotes: 1

Related Questions