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

Martin Honnen

thomas wrote:

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.

Could be a rights problem, make sure the account under which ASP is
exectued has the rights to access and overwrite that file.
 
C

Chris Lovett

You should also wrap this in an Application.Lock(), and Application.UnLock()
if you want to handle multiple concurrent requests safely.
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top