SrcCodes

How to retain DOCTYPE declaration while saving DOM Document to an XML file

If we save a DOM Document to an XML file using javax.xml.transform.Transformer, DOCTYPE declaration gets emitted by default. This example shows how we can retain PUBLIC and SYSTEM id of the DOCTYPE declaration for external DTD.

SrcCodes © 2026