使用 $element->children()
我无法获取当前元素的所有子元素。
但是如何使用 simplexml 获取当前元素的所有父元素?
假设它看起来像这样:
<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>
如果我当前的 $element
是 id=3
,我想获取 mac 和 apple 实体 ID。
这对 simplexml 是否可行,因为我找不到任何允许我这样做的函数?
最佳答案
$element->xpath("ancestor::entity/@id")
关于php - 在 php 中使用 simplexml 获取 xml 中的父元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2466153/