It's not a secret anymore!
The moose likes XML and Related Technologies and the fly likes writing back to a xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "writing back to a xml file" Watch "writing back to a xml file" New topic

writing back to a xml file

rupa kalid

Joined: Jul 26, 2000
Posts: 4
i am reading from an xml file, and posting the info as a jsp page,and after the changes are done by the user, i am writing the changes back to the document. How do i print the changed document back to the XML file???
i am using a dom parser
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
If it is a fairly simple DTD, you might just re-write the whole file by traversing the DOM and writing tags - pretty labor intensive but clear-cut.
Shama Khan
Ranch Hand

Joined: Aug 14, 2000
Posts: 185
I am using IBM's XML Parser for Java. I need to find out exactly which method(s) to use to save the DOM Tree to a file.
I've looked at O'reilly book and it has an example which is using org.jdom.output.XMLOutPutter (method) output;
I can't seem to find comparable class/method in the IBM project.

Manu Quartier

Joined: Oct 20, 2000
Posts: 10
Try this. I'm using xerces and xalan.
File file = new File("test.xml");
FileOutputStream output = new FileOutputStream(file);
XMLSerializer ser = new XMLSerializer(output, new OutputFormat(Method.XML, "ISO-8859-1", true));
PrintWriter pw = new PrintWriter(output);
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
The Java Examples in a Nutshell by David Flanagan has a class called XmlDocumentWriter which will write a Dom level 1 document to any OutputStream you pass to it. It strictly uses the org.w3c.dom package so, it'll work with any Package including Xerces, Oracle, IBM or JAXP. Check out the sample chapter on the Oreilly Network. Here:

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Sameer Rao

Joined: Oct 12, 2000
Posts: 20
Hello All,
Sorry to post a text out of context. But, I did not find much discussion on JODM anywhere in the ranch and saw a mention here, so posted my question here.
Has anyone used JDOM for XML ? JDOM is a parser that provides the flexibility of specifying which Vendor XML parser should be used for parsing the XML document. Also, JDOM builds a Document Object Model for the XML document (irrespective of the kind of parser used... SAX or DOM). This makes working with the XML entities easy. Try the website for more info.
I'd appreciate if anyone who has evaluated or worked with JDOM can comment.

ARS Kumar
Ranch Hand

Joined: May 22, 2000
Posts: 108
I am currently working on JDOM to create an XML file on the fly after the checkout option of a particular user. I did create the file outside the http/servlet world and is working good. I consider JDOM as a very easy way to go if somebody is interested in XML file manipulation with Java though I have a fear about that being still beta version ( at least the one installtion which I have !).
Can somebody thow some light onto how to pass the form parameters to the class which I have to create the XML file ?

ARS Kumar, Sun Certified Programmer for Java 2 Platform
I agree. Here's the link:
subject: writing back to a xml file
jQuery in Action, 3rd edition