Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing XML File via Java Program

 
Anbarasu Selvaraj
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends, It's regarding writing xml file via java program.

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);


In the above code it's displaying data's.


Now i want to write this data's to xml file. (How to process transformer value)

Please help me on this. Thanks.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to write it to a file instead of System.out? Then just change System.out to something which outputs to that file instead of to the console.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Xstream API .

Try it .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic