flex4: fx|XML - how to do complex search
i would like to search inside an fx|XML Object for a node with label='notifications'
and inside of it a node with label='notifications2'
and i want to get an XML contains what's in it.
this is my Flex 4 Code:
<?xml version="1.0" encoding="utf-8"?>
<s:Appli开发者_StackOverflow社区cation xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="_ccInit()">
<!-- Launch your application by right clicking within this class and select Debug As > FDT SWF Application -->
<fx:Declarations>
<fx:XML id="moshe">
<node state="root_item" label="notifications">
<node state="root_item" label="notifications2">
<node state="item" label="item" a="test1" b="test2" />
</node>
<node state="root_item" label="Winnings" />
<node state="root_item" label="Winnings2" />
<node state="root_item" label="Winnings3" />
<node state="root_item" label="Winnings4" />
<node state="root_item" label="Winnings5" />
</node>
</fx:XML>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private function _ccInit():void {
var newXml:XML = moshe.(@label == "notifications").(@label == "notifications2") as XML;
Alert.show(newXml.toString());
}
]]>
</fx:Script>
</s:Application>
newXml is null. how can i resolve the issue ?
thanks
Your search will never work. You dont define a rootTag for the moshe XML, and you cannot have root tag, 'nodes' and 'elements' with the same name i.e. node. You will have to have properly formatted XML.
A search for Flex XML Search on StackOverflow will give plenty of examples
精彩评论