Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Write/Append XML

Reply
Thread Tools

Write/Append XML

 
 
thomas
Guest
Posts: n/a
 
      05-16-2005
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>


 
Reply With Quote
 
 
 
 
Andy Dingley
Guest
Posts: n/a
 
      05-17-2005
On Mon, 16 May 2005 23:40:25 GMT, "thomas" <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
embedding xml in xml as non-xml :) Mark Van Orman XML 5 09-15-2004 05:57 AM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments