Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    updating XML with ASP

    Hi. I have an XML file which i'm trying to append elements to using an html form and ASP with javascript scripting inside the ASP file.

    The html is as follows:

    Code:
    <body>
    <form method="post" action="phonebook_js.asp">
    status <input type="text" name="status" id="status"><br>
    surname <input type="text" name="surname"><br>
    forename <input type="text" name="forename"><br>
    address <input type="text" name="address"><br>
    email <input type="text" name="email"><br>
    hometelno <input type="text" name="hometelno"><br>
    mobiletelno <input type="text" name="mobiletelno"><br>
    worktelno <input type="text" name="worktelno"><br>
    <input name="Submit" type="submit" value="Send" />
    </form></body>
    and the ASP file, phonebook_js.asp is as follows:

    Code:
    <%@ language="javascript"%>
    <html>
    <head>
    </head>
    <body>
    <%
    var xstatus = Request.Form("status");
    var xsurname = Request.Form("surname");
    var xforename = Request.Form("forename");
    var xaddress = Request.Form("address");
    var xemail = Request.Form("email");
    var xhometelno = Request.Form("hometelno");
    var xmobiletelno = Request.Form("mobiletelno");
    var xworktelno = Request.Form("worktelno");
    
    var xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    xmlDoc.load("http://panayiotou.fireflyinternet.co.uk/xml_with_asp/xmlfile.xml");
    
    var person = xmlDoc.createNode("element", "person", "");
    xmlDoc.documentElement.appendChild(person);
    
    var elementstatus = xmlDoc.createNode("element", "status", "");
    person.appendChild(elementstatus);
    elementstatus.text = xstatus;
    var elementsurname = xmlDoc.createNode("element", "surname", "");
    person.appendChild(elementsurname);
    elementsurname.text = xsurname;
    var elementforename = xmlDoc.createNode("element", "forename", "");
    person.appendChild(elementforename);
    elementforename.text = xforename;
    var elementaddress = xmlDoc.createNode("element", "address", "");
    person.appendChild(elementaddress);
    elementaddress.text = xaddress;
    var elementemail = xmlDoc.createNode("element", "email", "");
    person.appendChild(elementemail);
    elementemail.text = xemail;
    var elementhometelno = xmlDoc.createNode("element", "hometelno", "");
    person.appendChild(elementhometelno);
    elementhometelno.text = xhometelno;
    var elementmobiletelno = xmlDoc.createNode("element", "mobiletelno", "");
    person.appendChild(elementmobiletelno);
    elementmobiletelno.text = xmobiletelno;
    var elementworktelno = xmlDoc.createNode("element", "worktelno", "");
    person.appendChild(elementworktelno);
    elementworktelno.text = xworktelno;
    xmlDoc.save("http://panayiotou.fireflyinternet.co.uk/xml_with_asp/xmlfile.xml");
    xmlDoc = null;
    %>
    </body>
    </html>
    There must be some erro in the code because the whole thing just falls apart. Can anyone see where the problem is??? I'm going crazy here!!! Thanks.
    Last edited by mat106; 08-11-2004 at 10:22 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Debug by doing this:

    xmlDoc.load("http://panayiotou.fireflyinternet.co.uk/xml_with_asp/phonebook2.xml");
    var root = xmlDoc.documentElement;
    Response.Write("root:" + root); //if null, error in loading


    Does the xml you're trying to load exist in the same domain as the asp?
    I think you can't load external xml.

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The XML and ASP files are in the same domain and the same directory. I'll try the debugging you suggested...

  • #4
    New Coder
    Join Date
    Jun 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK. I've added
    Code:
    var root = xmlDoc.documentElement;
    Response.Write("root:" + root);
    after
    Code:
    var xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    xmlDoc.load("http://panayiotou.fireflyinternet.co.uk/xml_with_asp/xmlfile.xml");
    and removed everything after that just in case the error is somewhere furtherdown.

    When i fill in the form and submit it i get root:null . Does this mean the xml isn't loading? How do i fix it??? glenngv? Anyone?!?
    Last edited by mat106; 08-11-2004 at 10:22 AM.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Looking through my previous ASP app, I realized that the load() method expects a physical path not a virtual path. If the xml and asp are in the same domain and directory, then just specify the xml in the load method.

    xmlDoc.load("phonebook2.xml");

    or:

    xmlDoc.load(Server.MapPath("phonebook2.xml"));


  •  

    Posting Permissions

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