3 Replies Latest reply on Jun 23, 2009 7:33 PM by DaveFastFingers

    XML question: how to query for children without the grandchildren

    DaveFastFingers Level 1

      With an XML document:

       

      var xml:XML =

           <root>

                <L1 name="First">

                     <garbage/>

                </L1>

                <L1 name="Second">

                     <garbage/>

                </L1>

           </root>

       

      I need an XMLList of <L1> tags without their children, so the output should be:

       

      <L1 name="First">

      <L2 name="Second">

       

      Can someone help me with the actionscript syntaxt to accomplish this XML query? I haven't had success finding an example that doesn't return the children of the <L1> tags as well.

       

      Thanks,

      David

        • 1. Re: XML question: how to query for children without the grandchildren
          leybniz Level 4

          Well, if you need exact output you could use this line:

           

          trace(xml.toXMLString().match(/<\s*L1.*?>/g).join('\n'));

           

          this approach much faster than doing xmlfiltering + redundant garbage deletion, hope this helps

          • 2. Re: XML question: how to query for children without the grandchildren
            DaveFastFingers Level 1

            Interesting idea. Let me pose my actual scenario and see if you think this is still the right approach, or if maybe there's a better way.

             

            I want to feed this XMLList as a dataprovider to a Tree UI component, and I don't want the tree to render the <garbage/> tags, I just want one level rendered for now  (I'll update the tree data manually and add child nodes to the XML datasource programatically as the tree is traversed by the user).

             

            The full potential scope of the tree is huge, so I only want to render it as the user drills into particular sections.

             

            The XML I get just has some extra useless child tags in it (the <garbage/> tags in the example).

             

            Thanks again for the much appreciated help and advice!!

            David

            • 3. Re: XML question: how to query for children without the grandchildren
              DaveFastFingers Level 1

              Never mind, I worked out a better, or at least good method of doing this - My assumption that there were many objects wasn't correct. I built 2 data structures, one for the UI components (a pretty small set) for the Tree, and one for all the properties of only the component I was displaying at that particular moment (I was previously trying to fit everything into one data structure, presumably for simplicity, but getting quite the opposite result).

               

              Thanks again for the pointers! Very helpful!