A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Modify XML nodeValues

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    13
    Hi there,

    I'm trying to make a form that users can register and modify their info. There are three parts of information and I want to make it in a way that users can update one of them. The idea is to allow users to update part of their accounts with other parts stay intact. For example, they may want to update the admin info only and don't want to go through the firm info. The script I've come up with, however, appends the new value to the old ones without replacing them, so the data get messed up because of duplicated information. In addition, other parts of in the xml file that don't appear in the route (and as a result aren't written again to the original XML file) are gone. Any ideas please?


    The code:
    ================================================== ======
    _root.file_local = "http://localhost/"+getfile+".xml"; //getfile = username
    dbfile = new XML();
    dbfile.onLoad = modify;
    dbfile.load(file_local);

    function modify () {
    var arrayFirm = new Array("firm_name", "firm_address", "firm_city", "firm_state", "firm_zip", "firm_phone_areacode", "firm_phone_num1", "firm_phone_num2", "firm_fax_area", "firm_fax_num1", "firm_fax_num2");
    var arrayFirmValue = new Array(firm_name, firm_address, firm_city, firm_state, firm_zip, area_code, num1, num2, fax_area_code, fax_num1, fax_num2);
    var arrayAdmin = new Array("admin_first_name", "admin_last_name", "admin_email", "admin_username", "admin_password");
    var arrayAdminValue = new Array(firstname, lastname, email, username, password);

    for(var b=0; b<font><</font>arrayFirm.length;b++){

    foo.firstChild.firstChild.childNodes<font>[b]</font>.nodeValue = "";
    dbfile.firstChild.firstChild.childNodes.appendChil d((new XML()).createTextNode(arrayFirmValue));
    }

    for(var c=0; c<font><</font>arrayAdmin.length;c++){

    foo.firstChild.childNodes[1].childNodes[c].nodeValue = "";
    dbfile.firstChild.childNodes[1].childNodes[c].appendChild((new XML()).createTextNode(arrayAdminValue[c]));
    }

    entry = dbfile.toString();
    id = username
    file = id+".xml";
    loadVariablesNum ("http://localhost/dbxml.pl", 0, "POST");
    }
    [Edited by dafoc on 09-24-2001 at 05:10 PM]

  2. #2
    Junior Member
    Join Date
    Sep 2001
    Location
    Decatur, IN USA
    Posts
    21
    That's because you're using .appendChild...that will add a new child everytime...what you need to do is check and see if the child you're looking for already exists...if it does not, then use appendChild...if it does exist, then just modify the nodevalues

    Also, one suggestion...you might want to try using dbfile.send instead of loadvariablesnum...just a though...if you're happy with loadvariablesnum then just ignore that part of my message!

  3. #3
    Junior Member
    Join Date
    Feb 2001
    Posts
    13
    Thanks so much man! It works out after I make it modify nodeValues. Should have noticed it but thanks for your suggestion!!

    Could you help me figure out how to update just part of the XML file without erasing other parts? For example, say there are 4 parts of info on 4 pages. if a user wants to change somethings on one of them, and if the data is submited to the dame XML file, one that on that page will show up in the file. Is there anyway to prevent it?


    Thanks a lot!!

  4. #4
    Junior Member
    Join Date
    Sep 2001
    Location
    Decatur, IN USA
    Posts
    21
    Well, I'm not sure if I'm following your problem or not, but you can grab just one chain of the xml file and do with it whatever you want...

    temp = new XML();

    temp = dbfile.firstChild.childNodes[1];

    that will then hold whatever was inside of that childNode...hope that helps somehow...

  5. #5
    Junior Member
    Join Date
    Feb 2001
    Posts
    13
    This is what I did ... but it gives error message
    Any idea about what's going wrong?


    Code:
    ================================================== ========
    _root.file_local = "http://localhost/"+getfile+".xml";
    dbfile = new XML();
    dbfile.onLoad = modify;
    dbfile.load(file_local);

    function modify () {

    var arrayNode = new Array("firm_detail", "firm_portal_adminstrator_detail", "template_indentifier");
    var arrayFirm = new Array("firm_name", "firm_address", "firm_city", "firm_state", "firm_zip", "firm_phone_areacode", "firm_phone_num1", "firm_phone_num2", "firm_fax_area", "firm_fax_num1", "firm_fax_num2");
    var arrayFirmValue = new Array(firm_name, firm_address, firm_city, firm_state, firm_zip, area_code, num1, num2, fax_area_code, fax_num1, fax_num2);
    var arrayAdmin = new Array("admin_first_name", "admin_last_name", "admin_email", "admin_username", "admin_password");
    var arrayAdminValue = new Array(firstname, lastname, email, username, password);

    temp1 = new XML();
    temp1.appendChild((new XML()).createElement ("csi_ems:firm_detail"));
    for(var b=0; b<font><</font> arrayFirm.length; b++) {
    <br>
    temp1.firstChild.appendChild((new XML()).createElement ("csi_ems:" +arrayFirm[<font>b</font>]));
    temp1.firstChild.childNodes[<font>b</font>].appendChild((new XML()).createTextNode(arrayFirmValue[<font>b</font>]));
    }
    temp2 = new XML();
    temp2.appendChild((new XML()).createElement ("firm_portal_adminstrator_detail");
    for(var c=0; c<arrayAdmin.length; c++) {
    temp2.firstChild.appendChild((new XML()).createElement ("csi_ems:" +arrayAdmin[c]));
    temp2.firstChild.childNodes[c].appendChild((new XML()).createTextNode(arrayAdminValue[c]));
    }

    dbfile.firstChild.childNodes[0] = temp1;
    dbfile.firstChild.childNodes[1] = temp2;

    entry = dbfile.toString();
    id = username
    file = id+".xml";
    dbfile.send ("http://localhost/xmlDB.pl", 0, "POST");

    }

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