7 Replies Latest reply on Apr 1, 2010 11:34 AM by Flex harUI

    Stumped by this behavior when adding child to XML of XMLListCollection????

    rickcr Level 1

      Wow, this has be really stumped....

       

      I grab a flat xmlNode to a new XMLListCollection

       

      I add a child to that xmlNode XML

       

      I display the output of the XMLListCollection and its containing a node above it from somewhere else in the code? I'm totally lost to what is going on.

       

      //behind the scenes this XML exists:

      <prompt id="4"  label="Target">
          <prompt id="5" label="Internet Search"/>
           <prompt id="6" label="Demographics" />
      </prompt>

       

      I ger the xmlNode of prompt id = 6 which equates to :

      xmlNode  = <prompt id="6" label="Demographics" />

       

      //add it  XMListCollection

      [Bindable]

      prompt.demosSelected;

       

      prompt.demoSelected = new XMLListCollection(new  XMLList(xmlNode));

       

      LOG.debug("xmlListCollection before  appending to xmlNode = {0}", prompt.demosSelected.toXMLString());
      LOG.debug("xmlNode  before appending a child = {0}", prompt.xmlNode.toXMLString());
      prompt.xmlNode.appendChild(<foo  label="foobar"/>);
      LOG.debug("xmlNode after appending child =  {0}", prompt.xmlNode.toXMLString());
      LOG.debug("xmlListCollection  after appending to xmlNode = {0}", prompt.demosSelected.toXMLString());

       


      xmlListCollection  before appending to xmlNode =
      <prompt id="6" parentPromptID="4"  label="Demographics"/>

       

      xmlNode before appending a child =
      <prompt  id="6" parentPromptID="4" label="Demographics"/>

       

      xmlNode  after appending child =
      <prompt id="6" parentPromptID="4"  label="Demographics">
          <foo label="foobar"/>
      </prompt>

       

      xmlListCollection  after appending to xmlNode =
      <prompt id="5" label="Internet  Search"/> <!---- ******** HOW DID THIS GET HERE????? *******>
      <prompt  id="6" label="Demographics">
          <foo label="foobar"/>
      </prompt>

       

      formatting edited by: rickcr

        • 1. Re: Stumped by this behavior when adding child to XML of XMLListCollection????
          Flex harUI Adobe Employee

          Not sure, but instead of calling new XMLList(xmlNode), try recoding so you

          pass in the results of a query

           

          Xml.prompt.(id=="6")

          • 2. Re: Stumped by this behavior when adding child to XML of XMLListCollection????
            rickcr Level 1

            Still working on this. I've even narrowed down the behavior to a standalone piece of code you can run:

             

            http://pastie.org/897210

             

            Here are two screen shots of the before and after. What's interesting is somehow when I do the appendChild it's as if it affecting what else it decides to add. Very confusing. I really hope someone can take a peek at the code above.

             

            before:

             

            Screen shot 2010-03-31 at 11.52.58 AM.png

             

            after a race selected and "add" hit (Demographics folder is correctly added, but InternetSearch is a node that I would NOT expect to be added.)

             

            Screen shot 2010-03-31 at 11.53.09 AM.png

            • 3. Re: Stumped by this behavior when adding child to XML of XMLListCollection????
              rickcr Level 1

              Maybe there is just a general issue when trying to use an 'empty node' (no children) for the top level node that I want in a tree?

               

              For example, given this xml:

               

              [Bindable]

              private var spec:XML =
              <spec>
                  <prompt id="1" label="A"/>
                  <prompt id="2" label="B"/>
                  <prompt id="4" label="C">
                      <prompt id="5" label="D"/>
                      <prompt id="6" label="E"/>
                  </prompt>
              </spec>

               

              I want to use  <prompt id="6" label="E"/> as my top level node that I can add items to in a tree. As described in the previous message, this seems to have some issues, since for some reason when I try to add a child to <prompt id="6" label="E"/> it ends up tagging along the <prompt id="5" label="D"/> along with it.

               

              Is the issue in how I'm creating my XMLListCollection for gathering user selections?:

               

              [Bindable]
              private var selectedItemsCollection:XMLListCollection;

               

              private function creationComplete():void {
                   selectedItemsCollection = new XMLListCollection(new XMLList(spec..prompt.(@id == 6)));
              }

              • 4. Re: Stumped by this behavior when adding child to XML of XMLListCollection????
                rickcr Level 1

                sorry another side note, I also created my XMLListCollection without creating a new XMList just to see if it made a difference:

                 

                selectedItemsCollection = new XMLListCollection(spec..prompt.(@id == 6));

                 

                Yet still have the same issue that adding children to this collection ends up bringing in the node directly above it (on the same level) along with it in the tree.

                • 5. Re: Stumped by this behavior when adding child to XML of XMLListCollection????
                  rickcr Level 1

                  Wow, talk about confusion....


                  THIS ACTUALLY WORKS:


                  var xmlList:XMLList = selectedItemsCollection.source;
                  xmlList.appendChild(selectedItemNode);
                  selectedItemsCollection.source = xmlList;

                   

                  //by work I mean I end up WITHOUT the extra node showing up


                  THIS DOESN'T WORK (as expected):

                   

                  selectedItemsCollection.source.appendChild(selectedItemNode)


                   

                  When above is done I end up with an extra node showing above my current one (eg in this example you'll get <prompt id="5"> showing up even though I seed the tree only with <prompt id ="6"/>

                   

                  //starting xml

                  <spec>
                       <prompt id="1" label="A"/>
                       <prompt id="2" label="B"/>
                       <prompt id="4" label="C">
                           <prompt id="5" label="D"/>
                           <prompt id="6" label="E"/>
                       </prompt>
                  </spec>

                   

                  //seed the XMLListCollection for your tree with prompt id=6 node from above XML:

                  selectedItemsCollection = new XMLListCollection(spec..prompt.(@id == 6));

                   

                  <mx:Tree id="selectionsTree" width="100%" height="100%" allowMultipleSelection="true"
                      doubleClickEnabled="true" labelField="@label" dataProvider="{selectedItemsCollection}">

                  • 7. Re: Stumped by this behavior when adding child to XML of XMLListCollection????
                    Flex harUI Adobe Employee

                    Somehow a test case made it to my door.  I confirmed it is a bug in

                    HierarchicalCollectionView.  Please file a bug.