2 Replies Latest reply on Nov 14, 2008 11:56 AM by ericbelair

    Manipulating XML Node Values

    ericbelair Level 1
      I have an XML Object as a property of my Class. I want to dynamically update some of the values of the nodes. What is the best way to do this? Should I use XML.replace()?

      See attached pseudo code for my attempt.
        • 1. Re: Manipulating XML Node Values
          Level 7

          "ericbelair" <webforumsuser@macromedia.com> wrote in message
          news:gfk97h$60g$1@forums.macromedia.com...
          >I have an XML Object as a property of my Class. I want to dynamically
          >update
          > some of the values of the nodes. What is the best way to do this? Should I
          > use
          > XML.replace()?
          >
          > See attached pseudo code for my attempt.
          >
          > /* I start with this: */
          >
          > <Report>
          > <prop1>4</prop1>
          > <prop2>2255</prop2>
          > <prop3>true</prop3>
          > <prop4>false</prop4>
          > <prop5>true</prop5>
          > </Report>
          >
          > /* I want this result (change the value of node "prop5"): */
          >
          > <Report>
          > <prop1>4</prop1>
          > <prop2>2255</prop2>
          > <prop3>true</prop3>
          > <prop4>false</prop4>
          > <prop5>false</prop5>
          > </Report>
          >
          > /* I tried this: */
          >
          > var reportXML:XML =
          > <Report>
          > <prop1>4</prop1>
          > <prop2>2255</prop2>
          > <prop3>true</prop3>
          > <prop4>false</prop4>
          > <prop5>true</prop5>
          > </Report>;
          >
          > var myArray:Array = [{xmlNodeName: "prop5", value: false}];
          >
          > for each (var item:Object in myArray)
          > {
          > report.xml[item.xmlNodeName] =
          > reportSection.value.toString();
          > }

          Try

          report.xml.child(item.xmlNodeName).text() =
          reportSection.value.toString();


          • 2. Re: Manipulating XML Node Values
            ericbelair Level 1
            That didn't work for me. I also tried this:

            for each (var item:Object in myArray)
            {
            var itemXMLNode:String =
            "<" + item.xmlNodeName + ">"
            + item.value.toString()
            + "</" + item.xmlNodeName + ">";

            var itemXML:XML = new XML(itemXMLNode);

            report.xml.replace(item.xmlNodeName, itemXML);
            }


            ...but that didn't work either.