Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing back to a xml file

 
rupa kalid
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shama Khan
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manu Quartier
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sameer Rao
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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_
 
ARS Kumar
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic