5 Replies Latest reply on Jun 13, 2011 10:29 AM by Flex harUI

    Modify XML attribute

    Zolotoj Level 3

      I am trying to use the following to change attribute's value:

       

      trace(XML(tree.dataProvider)..menu.(@menuid == 12).@description2);

      XML(tree.dataProvider)..menu.(@menuid ==12).@description2 = htmlText;
      trace(XML(tree.dataProvider)..menu.(@menuid == 12).@description2);

       

      Both traces are the same, empty in my case. Any idea?

       

      Thanks

        • 1. Re: Modify XML attribute
          Flex harUI Adobe Employee

          There might be issues with trying to set a value on more than one item.

          Each query is an XMLList and could have more than one item in it.

           

          Try something like:

              XML(tree.dataProvider)..menu.(@menuid ==12)[0].@description2 = htmlText;

          • 2. Re: Modify XML attribute
            Zolotoj Level 3

            Does not look like it's helping.

            NewNode = XML(tree.dataProvider)..menu.(@menuid == 12)[0];

            NewNode looks like this:

            <menu name="General  Regulations" menuid="12" description2="">
              <menu name="Rule Gr-1" menuid="13" description2=""/>
              <menu name="Rule Gr-2" menuid="14" parentid="12" description2=""/>
              <menu name="Rule Gr-3" menuid="15" parentid="12" description2=""/>
              <menu name="Rule Gr-4" menuid="20" parentid="12" description2=""/>
            </menu>

             

            and

            XML(tree.dataProvider)..menu.(@menuid == 12)[0].@description2 = htmlText;

            has no effect.

            • 3. Re: Modify XML attribute
              Flex harUI Adobe Employee

              I assume htmlText is a simple string?  I'm not sure you can put angle

              brackets in an attribute without escaping it.

               

              Post a 20-line test case if you want us to take a closer look.

              • 4. Re: Modify XML attribute
                Zolotoj Level 3

                I was able to narrow down my code:

                 

                NewNode = XMLList(tree.dataProvider)..menu.(@menuid == 12);

                NewNode.@description2 = htmlText;

                trace(NewNode.@description2); // shows data

                 

                XMLList(tree.dataProvider)..menu.(@menuid == 12).@description2 = htmlText;
                trace(XMLList(tree.dataProvider)..menu.(@menuid == 12).@description2); // still empty.

                 

                What am I doing wrong here?

                • 5. Re: Modify XML attribute
                  Flex harUI Adobe Employee

                  In the first case, you are storing the XMLList of the query and working with

                  the elements in that XMLList.  In the second, you are running a second

                  query.  Seems like it should work anyway, but there must be some subtle

                  reason why it doesn't.