1 Reply Latest reply on Oct 11, 2007 3:51 AM by jagguy99

    xml add data problem

    jagguy99 Level 1
      i can add data to XML file but not in the right place.
      i load this from a file and want to add another author and title. I can do this but not in the correct place. How do i copy data back to a file?

      <author>mark twain</author>
      <title>huck finn</title>

      function showData():Void {

      xmlVal.ignoreWhite =true;

      var xRootNode:XMLNode =xmlVal.firstChild ; //books
      var bookTag:XMLNode =xRootNode.firstChild; //book
      // var att:Object =bookTag.attributes ;
      var xNew:XMLNode =new XMLNode (1, "author");
      var xNewText:XMLNode =new XMLNode (3, "marcus ee");
      var xNew2:XMLNode =new XMLNode (1, "title");
      var xNewText2:XMLNode =new XMLNode (3, "mytitile");

      xRootNode.appendChild (xNew);
      xRootNode.insertBefore (xNew,xRootNode);
      xNew.appendChild (xNewText);

      xRootNode.appendChild (xNew2);
      xNew2.appendChild (xNewText2);

      var aChild:Array =xRootNode.childNodes ;

      for (var i:Number=0 ;i<aChild.length;i++)

      trace(aChild .toString());

      output- last 2 lines should be inside book tags.i use insertBefore but it fails.

      <book><author>mark twain</author><title>huck finn</title></book>
      <author>marcus ee</author>