Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes XML and Related Technologies and the fly likes Editing data after retrieving from XML file and saving again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Editing data after retrieving from XML file and saving again" Watch "Editing data after retrieving from XML file and saving again" New topic
Author

Editing data after retrieving from XML file and saving again

Sana Ali
Greenhorn

Joined: Oct 08, 2004
Posts: 14
Hi
I am trying to load data from an xml file in a form edit that info and update the xml file.

Currently I am able to view some information in the form.

But when I try and save (plus go to another page to perform save and display function) i have the following code:

/* Start of serialization code */

File myFile = new File(fileName);

//write the XML out into a file on the filesystem of the web server
FileWriter writer = new FileWriter(myFile, false);

//Create a new OutputFormat
OutputFormat format = new OutputFormat();
format.setIndenting(true);

//Create a new XMLSerializer that will be used to write out the XML
//Pass to it the writer object that defines where the output will
//be written to, and the format object that defines the format in
//which the XML will be generated
XMLSerializer serializer = new XMLSerializer(writer, format);

// Call the serialize() method, and pass to it out XML document
// stored in memory in a DOM tree
serializer.serialize(document);

/* End of serialization code */

The problem is instead of changing the values of the existing data, my code adds the new information to a new node to the xml tree.=\

Please Help.
Sana
[ October 21, 2004: Message edited by: Sana Ali ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Moving to the XML forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Editing data after retrieving from XML file and saving again
 
Similar Threads
DOM : Set Encoding from Cp1252 to UTF-8
What Replaced org.apache.xml.serialize.XMLSerializer and org.apache.xml.serialize.OutputFormat
insert child node in xml adding and setting value
insert child node in xml adding and setting value
DOM and JAVA