3 Replies Latest reply on Nov 2, 2010 3:10 PM by Devtron

    parts of XML in hierachical data (like a tree)

    Manno Bult-to3djt Level 2

      Hi all,

       

      I have a potential rather large XML file of which I would like to present only parts in a tree structure. The XML is something like:

       

      <scenes>

       

       

           <scene id="1" label="a label">

       

                <actors>

                     ... stuff ...

                </actors>

       

                <snapshots>

       

                     <snapshot label="a label">

                          ... content of node ...

                     </snapshot>

                     <snapshot label="aother label">

                          ... content of node ...

                     </snapshot>

                     ... possibly more snapshots ...

                </snapshots>

           </scene>

           <scene label="a">

                <actors>

                     ... stuff ...

                </actors>

       

                <snapshots>

       

                     <snapshot label="a label">

                          ... content of node ...

                     </snapshot>

       

                     <snapshot label="aother label">

                          ... content of node ...

                     </snapshot>

                     ... possibly more snapshots ...

       

                </snapshots>

           </scene>

           ... more scenes ...

      </scenes>

       

      I would like to have a tree-like representation of it so that only 'scene' labels and 'snapshot' labels are shown.

       

      I can't figure out how to ignore all the subnodes without actually creating a copy of the XML and stripping them in some way. This I'd rather not do since the link between the actual data and it's visualization ( the tree ) is more or less gone.

       

      Suppose I'm a bit confused by all the possibilities... Maybe I can use a stripped XML but bind selections or changes (node's labels should be possible to be renamed and reordered) to the original data?

       

      Can someone point me in a right direction?

       

      Thanks in advance.

      Manno

        • 2. Re: parts of XML in hierachical data (like a tree)
          Manno Bult-to3djt Level 2

          Short but (/and?) spot on

           

          With some online examples it works ( in it's basic form ), now into the main thing...

           

          Thanks

          • 3. Re: parts of XML in hierachical data (like a tree)
            Devtron Level 3

            Wow, I wish I had known about [ITreeDataDescriptor] beforehand!!

             

            Another way to approach this is to assign the XML to an ArrayCollection and loop through the ArrayCollection, parsing out the strings you need.


            I was able to do this relatively easily to produce custom XML for my Trees (which use checkboxes in them!). It only took me a few hours and I thought it would take me weeks.

             

                            var XMLStr:String = "<accounts>\n";
                           
                            for each(var XMLNodeObj:Object in treeAC) {

             

                                        //if AccountID is not found in the new XML, process forward to obtain it

                                        if (XMLStr.search("AccountID=\"" +  XMLNodeObj.AccountID  ) == -1 ) {

                                              XMLStr += "<account label=\"" +  XMLNodeObj.AccountName + "\" AccountID=\"" +  XMLNodeObj.AccountID + "\" checked=\"0\"> \n"

             

                                              //getTreeAccountLocationXML is a string function that performs a search for other XML attributes needed

                                              XMLStr += getTreeAccountLocationXML(XMLNodeObj.AccountID ,treeAC);
                                              XMLStr += "</account> \n"

                                        }

             

                            }

             

                           //XML end tag

                           return XMLStr += "</accounts>"

             

             

             

             

             

             

            this code "checked=\"0\"> \n" " sets the "checked" property, which produces a checkbox in my Tree control for me....pretty damn cool.