开发者

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

开发者 https://www.devze.com 2022-12-16 05:43 出处:网络
Given this document: <doc> <element> <list> <key attr=\'val\'/> </list> </element>

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?


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


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

alternative

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消