Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with xml file  RSS feed

 
Joseph Bashir
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!