Append XML using ASP

Discussion in 'ASP General' started by thomas, Jun 26, 2005.

  1. thomas

    thomas Guest

    This should be pretty simple for you guys. I've been trying to append values
    to my XML file but I can't get it to work correctly.

    index.html passes the values of a form to the new_user.asp file and I want
    it to write my members.xml file.

    Once the xml file has been written and saved, I coded the ASP file to
    redirect to google, just to see if its working, which it does but the data
    has not been written to the XML file.

    Any ideas where I'm going wrong.

    index.html
    =======

    <html>
    <body>
    <form action="new_user.asp" method="post" name="new_user_form">
    <table>
    <tr>
    <td>
    <table>
    <tr>
    <td>Username:</td>
    <td><input name="Username" type="text"></td>
    </tr>
    <tr>
    <td>Email Address:</td>
    <td><input name="Email" type="text"></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input name="Password" type="password"></td>
    </tr>
    </table>
    <p><input type="submit" name="submit" value="submit"></p>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    new_user.asp
    =========

    <%@ Language=JScript%>

    <%

    var username = Request.Form("Username")
    var email = Request.Form("Email")
    var password = Request.Form("Password")

    var xmlDoc=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");
    xmlDoc.async="false";
    xmlDoc.load(Server.MapPath("/members.xml"));

    var nodeList = xmlDoc.getElementsByTagName("members");

    if(nodeList.length > 0){

    var parentNode = nodeList(0);
    var memberNode = xmlDoc.createElement("member");
    var usernameNode = xmlDoc.createElement("username");
    var emailNode = xmlDoc.createElement("email");
    var passwordNode = xmlDoc.createElement("password");

    usernameNode.text = username;
    emailNode.text = email;
    passwordNode.text = password;

    parentNode.appendChild(memberNode);
    memberNode.appendChild(usernameNode);
    memberNode.appendChild(emailNode);
    memberNode.appendChild(passwordNode);

    xmlDoc.save(Server.MapPath("/members.xml"));

    }

    Response.Redirect("http://www.google.co.uk")

    %>

    members.xml
    =========
    <members>
    <member>
    <username>thomas</username>
    <email></email>
    <password>123456</password>
    </member>
    </members>
    thomas, Jun 26, 2005
    #1
    1. Advertising

  2. thomas wrote:
    > This should be pretty simple for you guys. I've been trying to append
    > values to my XML file but I can't get it to work correctly.
    >
    > index.html passes the values of a form to the new_user.asp file and I
    > want it to write my members.xml file.
    >
    > Once the xml file has been written and saved, I coded the ASP file to
    > redirect to google, just to see if its working,


    Use Response.Write for your debugging. No need for rediredtion.

    > which it does but the
    > data has not been written to the XML file.
    >
    > Any ideas where I'm going wrong.
    >

    <snip - didn't really need to see that page ... >

    > new_user.asp
    > =========
    >
    > <%@ Language=JScript%>
    >
    > <%
    >
    > var username = Request.Form("Username")


    Response.Write(username + "<BR>")

    > var email = Request.Form("Email")
    > var password = Request.Form("Password")
    >
    > var xmlDoc=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");


    Nothing to do with your problem, but ... why "FreeThreaded"? Unless you're
    planning on storing the resulting object in Application or Session, you
    really should use the smaller, more efficient:

    var xmlDoc=Server.CreateObject("msxml2.DomDocument");

    > xmlDoc.async="false";
    > xmlDoc.load(Server.MapPath("/members.xml"));


    Response.Write(Server.HTMLEncode(xmlDoc.xml) + "<BR>")

    >
    > var nodeList = xmlDoc.getElementsByTagName("members");
    >


    response.Write("nodeList.length =" + nodeList.length + "<BR>")

    etc. The results of the Response.Writes should tell you where the problem
    is.

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Jun 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    0
    Views:
    508
    Ryan Ternier
    Apr 7, 2005
  2. terry

    Append xml record

    terry, Aug 6, 2004, in forum: Java
    Replies:
    2
    Views:
    4,800
    Brian Palmer
    Aug 6, 2004
  3. thomas

    Append XML using ASP

    thomas, Jun 26, 2005, in forum: XML
    Replies:
    2
    Views:
    3,130
    Chris Lovett
    Jun 29, 2005
  4. HYRY
    Replies:
    10
    Views:
    587
    Bruno Desthuilliers
    Sep 26, 2007
  5. RayLopez99
    Replies:
    16
    Views:
    4,524
    RayLopez99
    Aug 4, 2009
Loading...

Share This Page