I am using org.apache.xerces.dom.DocumentImpl to try and build a DOM to generate an XML document which does not use a System or Public ID but instead has the following structure:
<!DOCTYPE CATALOG_REQUEST [ <!ELEMENT CATALOG_REQUEST (CONFIG, UPDATEDATE+)> ...more stuff here... ]> <CATALOG_REQUEST> <CONFIG MERCHANTID="123" /> <UPDATEDATE TRANSID="abcd" YEAR="2000" MONTH="08" DAY="01"/> </CATALOG_REQUEST> I am trying to generate the DOM using the following code: DocumentTypeImpl docType = (DocumentTypeImpl) imp.createDocumentType("CATALOG_REQUEST", null ,null); docType.setInternalSubset(theWholeDtdAsAString); Document doc = imp.createDocument(null, "CATALOG_REQUEST" , docType); The problem is when I use org.apache.xml.serialize.XMLSerializer.serialize(Document); I get a <?xml version="1.0"?> instruction inserted between the DTD text and the XML text. And then if I parse the serialized file I get: org.xml.sax.SAXParseException: The XML declaration may only appear at the very beginning of the document suggestions?