1 Reply Latest reply on Dec 20, 2010 1:07 PM by kglad

    Adding data to XML objects.

    celebritymusic Level 1



      I'm wondering how to add completely new data to XML data I'm holding in a var.


      I'm importing XML data into an editor I'm creating.  The XML looks like this:




           <mediaFile order="1" playTime='2' transIn='1' transOut='9'>gif.gif</mediaFile> 
           <mediaFile order="2" playTime='1' transIn='6' transOut='8'>jpg.jpg</mediaFile>




      The code I've set up to contain the XML data is this:


      var theXML:XML;
      var myXML:XMLList;


      // function called when xml file loading is completed
      function onXMLLoaded_120 ( e:Event ) : void {
              // new instance of xml object
              theXML = new XML( e.target.data );
              // use XMLList object to filter child nodes of thumbnails
              myXML = theXML.itemList_120;


      etc - and it works to import the XML - if I trace (myXML), the above XML data gets displayed.


      I've figure out that you can change different parts of the XML data in myXML by doing this:


      myXML.mediaFile[1].@playTime = 2


      (which changes the second line of XML to this: <mediaFile order="2" playTime='2' transIn='6' transOut='8'>jpg.jpg</mediaFile> )

      My question is:


      Rather than change existing XML data, how do I add completely new data?  ie, if the above var held two "mediaFile" lines of XML, how do I add or insert a third?


      Thanks for taking a look at this.