Try this code : DocumentBuilder builder = factory.newDocumentBuilder(); final DOMImplementation domImplementation = builder.getDOMImplementation(); /* See this sttmt */ final DocumentType documentType = domImplementation.createDocumentType(rootName, /* this is null ?*/ xmlVersion.getPublicId(), xmlVersion.getSystemId());
documentType.setInternalSubset("..."); document = domImplementation.createDocument(null, rootName, documentType); Then Serialize the document object... -Prashant On Sun, 2008-01-13 at 19:31 +0530, Mukul Gandhi wrote: > I am using LSSerializer to serializing the DOM. Below is the complete code: > > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > DocumentBuilder docBuilder = dbf.newDocumentBuilder(); > > CoreDocumentImpl document = (CoreDocumentImpl)docBuilder.newDocument(); > > DocumentTypeImpl docType = > (DocumentTypeImpl)document.createDocumentType("root", null, null); > docType.setInternalSubset("<!ENTITY x 'hello'>"); > > Element root = document.createElement("root"); > Element a = document.createElement("a"); > root.appendChild(a); > EntityReference x = document.createEntityReference("x"); > a.appendChild(x); > a.appendChild(document.createTextNode(" world")); > > DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); > DOMImplementationLS impl = > (DOMImplementationLS)registry.getDOMImplementation("LS"); > LSSerializer writer = impl.createLSSerializer(); > LSOutput output = impl.createLSOutput(); > output.setByteStream(System.out); > writer.write(root, output); > > With this code, I am getting output: > > <?xml version="1.0" encoding="UTF-8"?> > <root> > <a>&x; world</a> > </root> > > But I also want internal DTD subset in the output. > > I guess, DocumentType node is not part of DOM data model, so is not > getting serialized (but then, what is the use of attaching > DocumentType node to the Document object ?). Am I correct to think so? > > Or, is this possible with Xerces-J? I am ready to use any Xerces > specific extensions. > > Will appreciate further help ... > > On Jan 13, 2008 3:49 PM, Dick Deneer <[EMAIL PROTECTED]> wrote: > > Are you using a Transformer class to serialize the document ? If so, > > then try to use the LSSerializer instead to serialize the DOM and you > > will also have the DTD subset in your output. > > > > > > Regards > > Dick Deneer > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]