Skip navigation
Currently Being Moderated

Construct mx:tree using xml dataprovider

Dec 11, 2012 1:35 AM

Dear All,

     How to construct the tree structure using following xml as dataprovider to mx:tree ?

     The xml is as follows,

 

<fx:XML id="employees">

     <employees>

         <employee ssn="123-123-1234">

             <name first="John" last="Doe"/>

             <address>

                 <street>11 Main St.</street>

                 <city>San Francisco</city>

                 <state>CA</state>

                 <zip>98765</zip>

             </address>

         </employee>

         <employee ssn="789-789-7890">

             <name first="Mary" last="Roe"/>

             <address>

                 <street>99 Broad St.</street>

                 <city>Newton</city>

                 <state>MA</state>

                 <zip>01234</zip>

             </address>

         </employee>

     </employees>

</fx:XML>

 
Replies
  • Currently Being Moderated
    Dec 12, 2012 7:35 AM   in reply to Supreet R

    you need to pass an xmlist (rather than xml) to the tree.

     

    from my distant memory, something like this should work:

     

    tree.dataProvider = new XMLList(employees.toString());

    tree.labelField = "@ssn";

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 13, 2012 3:44 AM   in reply to Supreet R

    Hi Supreet,

     

    I see above XML is not correct to display what you want to display

    Beacuse <street>11 Main St.</street> considered as parent node.

     

    as per my understanding from above code ,You want first street should be displayed, and in leaf node street name should be there(child item).

     

    you can modify your existing code as,

    1.XML

    <employee ssn="123-123-1234">

                       

                        <name first="John" last="Doe"/>

                       

                        <address>

                           

                            <street str= "street">

                               

                                <streetname street="11 Main St."/>

                            </street>   

                           

                            <city>San Francisco</city>

                           

                            <state>CA</state>

                           

                            <zip>98765</zip>

                           

                        </address>

                       

                    </employee>

    2.getTreeLabel method

    case "address":

                           

                        {

                           

                            lbl = item.name();

                           

                            break;

                           

                        }

                           

                        case "street":

                        {

                            lbl = item.@str;

                            break;

                        }

                        case "streetname":

                        {

                            lbl = item.@street;

                            break;

                        }

                           

                        case "city":

     

    Thanks,

    Kanchan Ladwani | kladwani@infocepts.com

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points