E4X可以根据任何级别的子节点的属性获取父节点的属性吗? [英] Can E4X Get Attribute of a Parent Node Based on Attribute of a Child At Any Level?

查看:33
本文介绍了E4X可以根据任何级别的子节点的属性获取父节点的属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个带有节点"的 XML 片段,它可以有无限的子节点"元素的子级别.

Consider this XML snippet with "nodes" which can have unlimited child levels of "subnode" elements.

我想根据 @id 为任何给定的 subnode 找到 node@type 属性> 属性.例如,如果我的 id 为 9,那么我想从上面返回 type="foo".

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

如何做到这一点?

推荐答案

您应该能够使用此 E4X 获取类型值:

You should be able to get the type value using this E4X:

xml.node.(descendants("subnode").@id.contains("8")).@type;

这篇关于E4X可以根据任何级别的子节点的属性获取父节点的属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆