Skip to main content

How to write XML document?

2 replies [Last post]
gsoap123
Offline
Joined: 2007-05-06
Points: 0

Hi,

I am referring to javax.xml.parsers.DocumentBuilder class.

This class has a method "parse" which returns us the Document object.

My question is how can I write that Document back to file system?

Is there any class which can write the XML document to file system?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
neunerball
Offline
Joined: 2005-11-22
Points: 0

You might want to look into JAXB as well, provided you have XML schema files

oleksiys
Offline
Joined: 2006-01-25
Points: 0

Hello,

Q. How do I output/marshal/serialize a DOM tree into a stream?

Previously, there was only one way to do this using JAXP, which required using the transform component. However, support for DOM Level 3 load and save was added in JAXP 1.4. Using this component, it is now possible to read an XML document into a DOM (load) and write a DOM into an XML document (save) in a platform-independent manner.

http://java.sun.com/webservices/jaxp/reference/faqs/index.html

////////////////////// Something like that should work ///////////////////////////
Document d = db.parse(document);

TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.transform(new DOMSource(d), );