Skip to Content
0
Former Member
Mar 15, 2007 at 11:27 AM

How to serialize a XML DOM Document

35 Views

I've a DOM Document, obtained from a file this way:

File f = new File("c:/file.xml");

DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = builderFactory.newDocumentBuilder();

Document doc = builder.parse(file);

[... code to modify doc ...]

<b>How can I serialize it back to a flat file ?</b>

I tried xalan libraries:

OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream());

java.util.Properties props = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);

Serializer ser = SerializerFactory.getSerializer(props);

ser.setWriter(osw);

DOMSerializer dser = ser.asDOMSerializer(); // a DOM will be serialized

dser.serialize(document);

But it doesn't find class '<b>OutputPropertiesFactory</b>'.

Help needed.

Best regards.