[英]get parent elements in xml with simplexml in php?
with $element->children()
i cant get all the child elements of current element. 使用
$element->children()
我无法获取当前元素的所有子元素。
but how can i get all the parent elements for current element with simplexml? 但是如何使用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. 如果我当前的
$element
是id=3
,我想获取mac和apple实体ID。
is this possible with simplexml cause i cant find any function allowing me to do this? simplexml是否可能导致我找不到任何允许我执行此操作的功能?
$element->xpath("ancestor::entity/@id")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.