473,503 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write/Append XML

I have the below form and I want the contents of the fields to be passed to
an ASP file which then writes them to an XML file. I've used a version of
this before, I then changed it but now it doesn't work. Any ideas?
new_user.html
==========
<html>
<head>
<title>New User</title>
<link href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="new_user.asp" method="post" name="new_user_form">
<table class = "one">
<tr>
<td>
<table class = "one">
<tr>
<td>Username:</td>
<td><input name="user" id="user" type="text" ></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="pass" id="pass" type="text"></td>
</tr>
</table>
<p><input type="submit" name="Submit" value="Confirm Details"></p>
<p><a href="index.html">Return to Login Page</a></p>
</td>
</tr>
</table>
</form>
</body>
</html>
new_user.asp
=========
<%@ Language="VBScript" %>

<%

dim objDom, fileExists, objFieldValue, objPI, nodes, path

Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
fileExists=objDom.Load(Server.MapPath("users.xml") )
If fileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("members")
objDom.appendChild objRoot
End If
Set objRecord = objDom.createElement("member")
objRoot.appendChild objRecord

Set objFieldValue = objDom.createElement("username")
objFieldValue.Text = Request.Form("user")
objRecord.appendChild objFieldValue

Set objFieldValue = objDom.createElement("password")
objFieldValue.Text = Request.Form("pass")
objRecord.appendChild objFieldValue
set xmlDocument=CreateObject("MSXML2.FreeThreadedDOMDo cument")
xmlDocument.async="false"
xmlDocument.load(Server.MapPath("users.xml"))
path = "members[user='" & lcase(Request.Form("user")) & "']"
set nodes = xmlDocument.selectNodes(path)
If nodes.length = 0 Then
If fileExists = False Then
Set objPI=objDom.createProcessingInstruction("xml", "version='1.0'")
objDom.insertBefore objPI, objDom.childNodes(0)
End If
Else
Response.Redirect("error.html")
End If
objDom.save(Server.MapPath("users.xml"))
Response.Redirect("success.html")

%>

%>
users.xml
======
<?xml version="1.0"?>
<members>
<member>
<username>thomas</username>
<password>123456</password>
</member>
<member>
<username>martin</username>
<password>111111</password>
</member>
<member>
<username>stuart</username>
<password>654321</password>
</member>
</members>
Jul 20 '05 #1
1 1559
On Mon, 16 May 2005 23:40:25 GMT, "thomas" <th***********@ntlworld.com>
wrote:
I have the below form and I want the contents of the fields to be passed to
an ASP file which then writes them to an XML file. I've used a version of
this before, I then changed it but now it doesn't work. Any ideas?


Diff it against the one that worked ?

(Oh, and you're being very free and easy with user-supplied data values.
Never trust a user.)

Really though I'd bin the whole page. Use a database, not XML. There's
a whole pile of multi-user locking problems you need to think about here
and your big monolithic XML file is just ignoring them all. This isn't
code that's anything like "web-ready" and it's more trouble to make it
so than it would be to just switch to a database.

XML isn't a database. It works with "documents", units of work that
roughly represent one transaction. The database analogy is the row of a
view (or maybe a view), not a table and certainly not a whole database.
You're performing a task here which will pretty much never need to
access the entire user list, just a single user - yet choosing XML
forces you to load, edit and save the whole set every time. That's just
a bad idea and fixing it (although possible) is harder than it would be
to do it by an easier method in the first place.

You never _have_ to use XML.
--
Cats have nine lives, which is why they rarely post to Usenet.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
4855
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
2
3089
by: jason hirst | last post by:
Hi, I've created a simple application that reads data from a SQL Server, and appends this to an XML file. The problem is, that the XML data structure seems to go to the top level when I write...
9
6327
by: msuk | last post by:
All, I have a well form block of XML that is stored in a C# string type and I just simply want to display it in the browser using Response.Write but when I try this I get the following error: ...
4
1132
by: JenHu | last post by:
Hi all, I want to retrieve data from database and generate a string line with fix length characters, so I can put into a file. But this is the first time I am writing module besides ASP.NET. I...
6
17097
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
6
2600
by: jonathan184 | last post by:
Hi I am trying to write a line to a file but i want it to write to line 1 of the file and push down what was on line 1. The code below works but inserts the line to the bottom of the page and i...
9
6913
by: andy.z | last post by:
If 2 people try to access the same text file at the same time to write to it - what happens in PHP ? What I mean is - presumably the first will be ok - But what will the second person actually...
16
4650
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
1
5779
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). If the file doesn't exist,...
2
1804
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). Therefore, I want to...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.