Adding a child node to XML in flex

14,892

If you are using flex, use AS3. XMLNode is AS2. In short, try this:

tree = <node label="Root">
           <node label="Category 1"/>
           <node label="Category2"/>
           <node label="Category3"/>
           <node label="Category 4">
               <node label="SubCategory4.1"/>
               <node label="SubCategory4.2"/>
           </node>
       </node>;
var someNode:XML = <node label="Category5"/>;
var aSubNode:XML = <node label="SubCategory5.1"/>;
someNode.appendChild(aSubNode);
tree.appendChild(someNode);
Share:
14,892
Sergiu Z
Author by

Sergiu Z

VP of Engineering at Insightful Science

Updated on June 04, 2022

Comments

  • Sergiu Z
    Sergiu Z about 2 years

    In a Flex application, I'm have an xml object that I'm binding to a tree control. I'm able to add a child node to the xml but when I try to add a child to the child node it doesn't appear on the tree control

    tree =  <node label="Root">
                            <node label="Category 1"/>
                            <node label="Category2"/>
                            <node label="Category3"/>
                            <node label="Category 4">
                                <node label="SubCategory4.1"/>
                                <node label="SubCategory4.2"/>
                            </node>
                        </node>;                    
                var someNode:XMLNode = new XMLNode(9, 'Category5');         
                var aSubNode:XMLNode = new XMLNode(9, 'SubCategory5.1');
                someNode.appendChild(aSubNode);                                 
                tree.appendChild(someNode);
    

    So Category5 appears on the tree control but SubCategory5.1 does not. What am I missing?