Append XML using ASP

T

thomas

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 protected]</email>
<password>123456</password>
</member>
</members>
 
B

Bob Barrows [MVP]

thomas said:
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.
new_user.asp
=========

<%@ Language=JScript%>

<%

var username = Request.Form("Username")

Response.Write(username + said:
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) + said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top