I have XML with the following structure, for example
<root>
<node flag="false"/>
<node flag="true"/>
<node flag="false"/>
<node flag="false"/>
<node flag="true">
<node flag="false"/>
<node flag="true"/>
<node flag="false"/>
<node flag="true"/>
</node>
<node flag="true"/>
<node flag="false">
<node flag="false"/>
<node flag="true"/>
<node flag="false"/>
<node flag="true"/>
</node>
<node flag="false"/>
</root>
All children have name "node". What I need is to get an XMLList (or XML, no matter), with the same hierarchy, but containing only nodes with the flag "true".
The result I need for my example is:
<root>
<node flag="true"/>
<node flag="true">
<node flag="true"/>
<node flag="true"/>
</node>
<node flag="true"/>
</root>
Is there any nice way to do this using e4x (without iterating through loop)? I tried to do the following: xml.node.(@flag=="true"), but the result in this case is:
<root>
<node flag="true"/>
<node flag="true">
<node flag="false"/> <!--need to kill this node-->
<node flag="true"/>
<node flag="false"/> <!--need to kill this node-->
<node flag="true"/>
</node>
<node flag="true"/>
</root>
Any ideas? Thank you!
Here a one liner in
e4x
as you ask :it delete the node to the current
XML
so pay attention to have a copy of your current XML.By the way you should know that
e4x
just do a loop under the hood, and that one liner will not be faster than a custom loop.