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

Given this document:

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

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

+4
source share
3 answers
 ..element.( list.key.@attr == "val") 
+2
source
 xmlVarName.element.list.key.(@attr=="val"); 

alternative

 xmlVarName..key.(@attr=="val"); 
+2
source

It is important to note that

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

May fail if the nodes not everyone is @attr .

The safest (albeit in my experience, not 100% successful) method for retrieving a node list.

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

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

+1
source

All Articles