可以E4X获取父节点的属性基于对孩子的属性在任何层次? [英] Can E4X Get Attribute of a Parent Node Based on Attribute of a Child At Any Level?
问题描述
考虑这个XML片断与节点,它可以有子节点元素无限子级别。
Consider this XML snippet with "nodes" which can have unlimited child levels of "subnode" elements.
我想找到节点
对于任何给定的子节点<
@type
属性/ code>,是根据它 @Id
属性。举例来说,如果我有9一个id,然后我想从上面返回值的类型=富。
I want to find @type
attribute of the node
for any given subnode
, based on its @id
attribute. For example, if I have an id of 9 then I want to return the type="foo" from above.
<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我想出了,但失败是:
The E4X I have come up with, but which fails is:
xml.node.(subnode.(@id == '8')).@type
那种
我明白为什么这是行不通的。什么更有意义的是以下但语法失败(在AS3):
I can kind of see why it doesn't work. What would make more sense is the following but the syntax fails (in AS3):
xml.node.(..subnode.(@id == '8')).@type
如何才能做到这一点?
How can this be done?
推荐答案
您应该能够得到使用这种E4X的类型值:
You should be able to get the type value using this E4X:
xml.node.(descendants("subnode").@id.contains("8")).@type;
这篇关于可以E4X获取父节点的属性基于对孩子的属性在任何层次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!