473,651 Members | 2,917 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.c ss" rel="stylesheet " type="text/css">
</head>
<body>
<form action="new_use r.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.htm l">Return to Login Page</a></p>
</td>
</tr>
</table>
</form>
</body>
</html>
new_user.asp
=========
<%@ Language="VBScr ipt" %>

<%

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

Set objDom = server.CreateOb ject("Microsoft .XMLDOM")
objDom.preserve WhiteSpace = True
fileExists=objD om.Load(Server. MapPath("users. xml"))
If fileExists = True Then
Set objRoot = objDom.document Element
Else
Set objRoot = objDom.createEl ement("members" )
objDom.appendCh ild objRoot
End If
Set objRecord = objDom.createEl ement("member")
objRoot.appendC hild objRecord

Set objFieldValue = objDom.createEl ement("username ")
objFieldValue.T ext = Request.Form("u ser")
objRecord.appen dChild objFieldValue

Set objFieldValue = objDom.createEl ement("password ")
objFieldValue.T ext = Request.Form("p ass")
objRecord.appen dChild objFieldValue
set xmlDocument=Cre ateObject("MSXM L2.FreeThreaded DOMDocument")
xmlDocument.asy nc="false"
xmlDocument.loa d(Server.MapPat h("users.xml" ))
path = "members[user='" & lcase(Request.F orm("user")) & "']"
set nodes = xmlDocument.sel ectNodes(path)
If nodes.length = 0 Then
If fileExists = False Then
Set objPI=objDom.cr eateProcessingI nstruction("xml ", "version='1.0'" )
objDom.insertBe fore objPI, objDom.childNod es(0)
End If
Else
Response.Redire ct("error.html" )
End If
objDom.save(Ser ver.MapPath("us ers.xml"))
Response.Redire ct("success.htm l")

%>

%>
users.xml
======
<?xml version="1.0"?>
<members>
<member>
<username>thoma s</username>
<password>12345 6</password>
</member>
<member>
<username>marti n</username>
<password>11111 1</password>
</member>
<member>
<username>stuar t</username>
<password>65432 1</password>
</member>
</members>
Jul 20 '05 #1
1 1570
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
4876
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
2
3115
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 the file. By this, I mean, if my original XML file looks like... <?xml version="1.0" encoding="utf-8" ?>
9
6336
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: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
4
1138
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 need help from you. I wrote the code like this, and I don't how to put into a string line........can someone show me how to do it. The output should like this:
6
17130
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
2606
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 need the line to append to line1. Could somebody help me out on how to do do this please. #!/usr/bin/perl $| = 1;
9
6928
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 see in his browser? And what will php do about it if not specifically programmed to deal with it ie whats the default behaviour?
16
4680
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) free hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the PHP info below shows ... Test it at: http://home.no.net/moldevbk/fopen-test/?mode=w (write - fails) http://home.no.net/moldevbk/fopen-test/?mode=a (append - ok)...
1
5801
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, create the file and write from the beginning. Therefore, I want to code this like below: FileInfo lFile = new FileInfo("C:\\temp\\debug.txt"); if (lFile.Exists)
2
1818
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 code this like below: FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");
0
8357
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8803
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4144
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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 we have to send another system
2
1588
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.