aspose file tools*
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
Author

writing back to a xml file

rupa kalid
Greenhorn

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
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
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.
Bill

Java Resources at www.wbrogden.com
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.
Shamima


Shama
Manu Quartier
Greenhorn

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);
ser.setOutputCharStream(pw);
ser.asDOMSerializer();
ser.serialize(dataDOM.getDocumentElement());
Carl Trusiak
Sheriff

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: http://www.oreilly.com/catalog/jenut2/chapter/ch19.html


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

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 www.jdom.org for more info.
I'd appreciate if anyone who has evaluated or worked with JDOM can comment.
<raosv@rocketmail.com>
------------------
_SvR_

_SvR_
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 ?
thanks
ARSKumar

ARS Kumar, Sun Certified Programmer for Java 2 Platform
http://www.automatedsqa.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing back to a xml file
 
Similar Threads
Most direct way of going from an Object to a XML String using JAXB?
Preserving DOCTYPE using JAXP 1.2
How to create a hierarchy using the following xml file
Using XML Signatures from JWSDP with JDOM
help regarding createing node in xml file