tags:

views:

194

answers:

1

with $element->children() i cant get all the child elements of current element.

but how can i get all the parent elements for current element with simplexml?

lets say it looks like this:

<entity id=1>
   <name>apple</name>
   <entities>
      <entity id=2>
         <name>mac</name>
         <entities>
            <entity id=3>
               <name>safari</name>
            </entity>
         </entities>
      </entity>
   </entities>
</entity>

if my current $element is id=3, i want to get the mac and apple entity ids.

is this possible with simplexml cause i cant find any function allowing me to do this?

+2  A: 
 $element->xpath("ancestor::entity/@id")
Tomalak
could you explain "ancestor::entity/@id" for me?
never_had_a_name
It selects the `id` attribute of all ancestor `<entry>` nodes. Learn XPath, it's really not hard. ;)
Tomalak