What is the Flex/AS3/E4X equivalent of this xpath query?

不打扰是莪最后的温柔 提交于 2019-12-07 11:22:21

问题


Given this document:

<doc>
    <element>
        <list>
            <key attr='val'/>
        </list>
    </element>
    <element>
        <list>
            <key attr='other'/>
        </list>
    </element>
    <element>
        <list/>
    </element>
</doc>

I want an e4x equivalent of the xpath //element[list/key/@attr="val"]. Is it possible to do that?


回答1:


..element.(list.key.@attr == "val")



回答2:


xmlVarName.element.list.key.(@attr=="val");

alternative

xmlVarName..key.(@attr=="val");



回答3:


It is important to note that

..element.(list.key.@attr == "val")

Can fail if the key nodes don't all have @attr.

The safest (although in my experience, not 100% successful) method to extract your node list would be.

..element.(list.key.attribute("attr") == "val")

However, I have had problems with e4x and conditional expressions, (AS3 implementation, Mozilla seems better.) but it seems to be down to the xml source.



来源:https://stackoverflow.com/questions/2068316/what-is-the-flex-as3-e4x-equivalent-of-this-xpath-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!