dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Updating XML, creating new nodes

  1. #1
    Junior Member
    Join Date
    Jun 2002
    Posts
    10

    Exclamation

    Greetings All,

    What I want do is load some XML in flash, make changes to it and then send it back to the db. My question is what is the best way to add nodes to my XML and update elements in my XML?

    XML.createElement looks like it creates elements, how to I set the values of the elements I have created?

    Can I use XML.nodeValue = Updated value? Is there another or better way?

    Awesome thanx, I have no problems getting the XML in or sending it off Just not sure how to edit it within flash.

    Z

  2. #2
    Junior Member
    Join Date
    Jun 2002
    Posts
    10
    One easy way I've found is to load the XML children into an array. Then you can format the XML node as a text string, eg:

    XMLNode ="<testnode><name>" + name + "</name></testnode>";
    XMLArray[XMLArray.length] = XMLNode;

    To update a node you'd do the same but by writing over the same array element with the newly formatted one.

    I'm still not sure about how to get the array elements back into XML format to use XML.send. So let me know if you've done this.

    So to get the XML into array I go:

    tagList = new Array;
    tagList = input.firstChild.childNodes; // where input is an xml node

    Can I go
    input.firstChild.childNodes = tagList ??

    Hopefully

    Awesome Z.


  3. #3
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    Have a look at the Macromedia XML docs, childNodes is an array and can be treated as such. Anything you can do to an array you can do to childNodes. However to add records you will need to use the appropriate function.

    Thanks

    Luke


  4. #4
    Junior Member
    Join Date
    Jun 2002
    Posts
    10
    Thanks dude.

    Basically I have an array which has XML child loaded into each element - standard approach here.

    tagList = input.firstChild.childNodes; //get tags from input XML
    childList = tagList[0].childNodes; //populate array list

    Then I want to add XML children to the array. However when I add a value to the array eg:

    childList[index] = "<xml>vars</xml";

    flash doesn't recognise the text as XML, leading me to guess that I need to create a new XML object, and use the XML methods createElement and createTextNode to do this. There are no examples in the manual on how to do this :-)

    Alternatively I could try cloning another node:

    node = doc1.lastChild.cloneNode(true);
    doc2.appendChild(node);

    However I am not sure how to update nodeValues or if this is possible.

    If anyone else out there has solved this problem I'd like to hear from you In the meantime I'll be having a play

    Thanx all,
    Z.




  5. #5
    Junior Member
    Join Date
    Jun 2002
    Posts
    10
    And I lost the rest of the post

    Here's one solution, although hardly elegant

    node_test = hoursList[index].cloneNode(true);
    nodeList = node_test.childNodes
    for(z=0;z<=nodeList.length;z++) {

    if(nodeList[z].nodeName=="comments"){
    nodeList[z].firstChild.nodeValue = "updated value";
    }
    }

    I'm going to try the createElement, createTextNode methods.

    Z.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center