开发者

get parent elements in xml with simplexml in php?

开发者 https://www.devze.com 2022-12-23 12:47 出处:网络
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?

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:

&l开发者_如何转开发t;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?


 $element->xpath("ancestor::entity/@id")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号