...

View Full Version : updating XML with ASP



mat106
08-10-2004, 08:34 PM
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:


<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:


<%@ 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.

glenngv
08-11-2004, 04:18 AM
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.

mat106
08-11-2004, 09:48 AM
The XML and ASP files are in the same domain and the same directory. I'll try the debugging you suggested...

mat106
08-11-2004, 09:55 AM
OK. I've added

var root = xmlDoc.documentElement;
Response.Write("root:" + root);

after

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?!?

glenngv
08-12-2004, 03:14 AM
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"));



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum