Reputation: 5892
Using Saxon S9API, what is the idiomatic way to serialize a DOM document to output stream? Something like
Serializer result = processor.newSerializer(out);
XdmNode source = processor.newDocumentBuilder().build(new DOMSource(doc));
result.serializeNode(source);
works but is there more correct way in S9API?
Upvotes: 1
Views: 262
Reputation: 163498
You don't want to do DocumentBuilder.build()
because that will copy the whole DOM to a tree using the default tree model (normally a TinyTree). Instead you can use DocumentBuilder.wrap()
(supplying the DOM Document node) which simply creates an XdmNode as a wrapper around the DOM node.
So:
Serializer result = processor.newSerializer(out);
XdmNode source = processor.newDocumentBuilder().wrap(doc);
result.serializeNode(source);
Upvotes: 2