Forums Register Login

Problem with xml file

+Pie Number of slices to send: Send
Using org.w3c.dom package I have written code to generate .xml file. i.e.

<?xml version="1.0" encoding="UTF-8"?>
<Users>
<User>
<FirstName>Peter</FirstName>
<LastName>Johnson</LastName>
<UserName>peter</UserName>
<Password>1234567</Password>
<Email>peter@petersdomain.com</Email>
</User>
</Users>

The data for the xml file comes from a HTML Form. Everytime I submit the HTML Form, the data in the xml file is over-written by the new data.

What I want is that everytime I submit the HTML Form, the new data should be added and the old data should also exist. Can someone please tell me the solution. Here are few of the line of code;

Element main,root,item;

main = doc.createElement("Users");
main.appendChild(doc.createTextNode("\n"));

root = doc.createElement("User");
root.appendChild(doc.createTextNode("\n"));

item = doc.createElement("FirstName");
item.appendChild(doc.createTextNode(first_name));
root.appendChild(item);
root.appendChild(doc.createTextNode("\n"));

item = doc.createElement("LastName");
item.appendChild(doc.createTextNode(last_name));
root.appendChild(item);
root.appendChild(doc.createTextNode("\n"));

Thanks
[ July 12, 2005: Message edited by: Joseph Bashir ]
+Pie Number of slices to send: Send
You aren't telling us how you are creating your Document instance. I have a feeling you are creating an empty document and saving it over the existing one. Have a look at this example.
If that's not the problem than this line probably is:

I'm not sure, but I'll bet that if you create a new root Element with the same name as an existing one, the new Element replaces the old and wipes out your previous User node.
By the way, don't bother with the newline text nodes. XML isn't supposed to be a readable text document. Those newlines will just pollute your DOM and make navagating it more difficult.
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1026 times.
Similar Threads
Sun XML DOM DocumentBuilder Obj fails when called by a Servlet
crimson error encountered
making changes to an xml document...help needed!
Can you post data from textfields to a URL without having a <form>
Can't use MySQL connection pool?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:44:16.