How to save DOM structure into XML file?

A

Alex

I need to save my object into XML file.
I am looking for something like myDomStucture.storeIntoXMLFile() that
saves it into XML file. Not parsing my object and outputting line by
line into XML file.

Thanks
 
K

kookey

do u means this is "line by line" ?
public void transformDomToXml(Document doc,String fileName){
try{
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(fileName));
transformer.transform(source,result);
}catch (TransformerConfigurationException tce) {
System.out.println("exception1:" + tce.getMessage() );
}catch (TransformerException te) {
System.out.println("exception2:" + te.getMessage() );
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top