Hai Madhavi,

Try this one.... may be this could help u....

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute"
creationComplete="convertXMLtoArrayColl();">
<mx:Script>
    <![CDATA[
        import mx.rpc.xml.SimpleXMLDecoder;
        import mx.controls.Alert;
        import mx.collections.ArrayCollection;
        [Bindable]
        public var arrColl:ArrayCollection;
        [Bindable]
        private var treeData:XML =
               <root>
                <node label="CRM" data="222">
                     <test label="aaa" data="333"/>
                     <test label="bbb" data="444"/>
                     <test label="ccc" data="555"/>
               </node>
               <node label="ERP" data="666">
                    <test label="ddd" data="777"/>
                    <test label="eee" data="888"/>
                    <test label="fff" data="999"/>
               </node>
                <node label="BI" data="000">
                    <test label="ggg" data="1010"/>
                     <test label="hhh" data="1111"/>
                   <test label="iii" data="2222"/>
               </node>
               </root>;
        public function convertXMLtoArrayColl():void{
           Alert.show("entred into the function");
           var xmlDoc:XMLDocument = new XMLDocument(treeData);
           var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
           var data:Object = decoder.decodeXML( xmlDoc );

            arrColl=new ArrayCollection();

            if(data.root.hasOwnProperty("node"))
            {
               for each(var xx:XML in treeData.node)
               {
                      trace(xx);
                   var xmlDoc1:XMLDocument = new XMLDocument(xx);
                   var decoder1:SimpleXMLDecoder = new
SimpleXMLDecoder(true);
                   var data1:Object = decoder1.decodeXML( xmlDoc1 );

                    for each(var obj:Object in data1.node.test)
                    {
                        arrColl.addItem(obj);
                    }

               }

               }
        }
    ]]>
</mx:Script>

</mx:Application>

Cheers,
Prakash Avula.

On Thu, Jan 27, 2011 at 3:58 PM, madhavi chinni <[email protected]
> wrote:

> Hi,
>
> I want to convert and xml into ArrayCollection.I have tried to do it
> using SimpleXMlDecoder.When I have converted the xml into
> ArrayCollection I am only able to access the elements just below the
> root node.I am unable to access the inner elements.
> Please find the code below:
>
> [Bindable]
> public var arrColl:ArrayCollection;
> [Bindable]
> private var treeData:XML =
>        <root>
>                 <node label="CRM" data="222">
>                      <test label="aaa" data="333"/>
>                      <test label="bbb" data="444"/>
>                      <test label="ccc" data="555"/>
>                </node>
>                <node label="ERP" data="666">
>                     <test label="ddd" data="777"/>
>                     <test label="eee" data="888"/>
>                     <test label="fff" data="999"/>
>                </node>
>                 <node label="BI" data="000">
>                     <test label="ggg" data="1010"/>
>                      <test label="hhh" data="1111"/>
>                    <test label="iii" data="2222"/>
>                </node>
>        </root>;
> public function convertXMLtoArrayColl():void{
>                                Alert.show("entred into the function");
>                                var xmlDoc:XMLDocument = new
> XMLDocument(treeData);
>                                var decoder:SimpleXMLDecoder = new
> SimpleXMLDecoder(true);
>                                var data:Object = decoder.decodeXML( xmlDoc
> );
>
> arrColl=new ArrayCollection();
>
> if(data.root.hasOwnProperty("node"))
>                                {
>                                        if(data.root.node is
> ArrayCollection)
>                                        {
>                                                arrColl = data.root.node;
>
>            }
>                                        else if(data.root.node is Object)
>                                        {
>
>  arrColl.addItem(data.root.node);
>
>            }
>                                }
>
> }
>
> I want to access the <test> element which is there inside the node
> element.
> Can anyone please let me know how can I do this
>
> --
> You received this message because you are subscribed to the Google Groups
> "Flex India Community" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<flex_india%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/flex_india?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to