考虑这个带有“节点”的 XML 片段,它可以有无限的“子节点”元素的子级别。
我想根据其@type
属性找到node
任何给定的属性。例如,如果我的 id 为 9,那么我想从上面返回 type="foo"。subnode
@id
<xml>
<node type="bar">
<subnode id="4">
<subnode id="5"/>
</subnode>
<subnode id="6"/>
</node>
<node type="foo">
<subnode id="7">
<subnode id="8">
<subnode id="9"/>
</subnode>
</subnode>
<subnode id="10"/>
</node>
</xml>
我想出的 E4X 但失败的是:
xml.node.(subnode.(@id == '8')).@type
我可以明白为什么它不起作用。更有意义的是以下内容,但语法失败(在 AS3 中):
xml.node.(..subnode.(@id == '8')).@type
如何才能做到这一点?