I have a DOM Document created from scratch and I need to serialize it to an output stream. I am using DOM level 3 serialization API, like in the following example:
OutputStream out;
Document doc;
DOMImplementationLS domImplementation =
(DOMImplementationLS) DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
LSOutput lsOutput = domImplementation.createLSOutput();
lsOutput.setByteStream(out);
lsSerializer.write(doc, lsOutput);
I need to have inside the resulting document a DOCTYPE declaration with both public and system identifiers, but I was not able to find a way to produce it.
How can I do?