• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Saving an on the fly generated Xml document

Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I have generated an XML document onthe fly using Servlets. I want to store the newly generated document as ,say , delstar.xml.
Previously, i.e when I used the older xml api, I used to write:
doc.write(new FileOutputStream("delstar.xml"));
// where doc is the XmlDocument.
However using the Java API for XML Processing 1.1ea2, I am getting the following error:

---------- compile ----------
CreateDom.java:63: cannot resolve symbol
symbol : method write (java.io.FileOutputStream)
location: interface org.w3c.dom.Document
doc.write(new FileOutputStream("aamir.xml"));
1 error
Normal Termination
Output completed (10 sec consumed).
Can someone suggest me the alternative.

Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try org.dom4j.io.XMLWriter class.To access the same u need to have dom4j.jar.Which is freely available from http://dom4j.org
So in your case the code would be
FileOutputStream file=new FileOutputStream("delstar.xml");
XMLWriter writer=new XMLWriter(file);
writer.write(document); //document refers to object of XML document
Hope this will work fine.
Best Regards
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!