First, you should create the document with the document type as follows:

  DOMImplementation impl;

  impl = new DOMImplemenation();
  doc = impl.createDocument( null, "dibob", impl.createDocumentType(
"dibob", null, "dibob.dtd" ) );

Second, you should try getting the latest Xerces release from the CVS,
since it contains bug fixes to the document type printing code. It's not
working in 1.0.1, almost always working in 1.0.2, but has two bug fixes
in the CVS version (since two days ago).

arkin



"Wiedmann, Jochen" wrote:
> 
> Hello,
> 
> the question may be stupid, but how do I create a doctype specification in
> a serialized document? Here's what I do, I'd expect to see a doctype
> declaration in the output, but I only get XML declaration and document.
> 
> Thanks,
> 
> Jochen
> 
>   public class domtest {
>     public static void main (String args[]) throws java.io.IOException {
>         org.apache.xerces.dom.DocumentImpl myDoc =
>             new org.apache.xerces.dom.DocumentImpl();
>         org.w3c.dom.DocumentType dt =
>             new org.apache.xerces.dom.DocumentTypeImpl(myDoc, "dibob", null,
>                                                        "dibob.dtd");
>         myDoc.appendChild(dt);
>         myDoc.appendChild(myDoc.createElement("dibob"));
> 
>         org.apache.xml.serialize.OutputFormat oformat =
>             new org.apache.xml.serialize.OutputFormat("XML", "iso-8859-1",
>                                                       true);
>         oformat.setDoctype(null, "dibob.dtd");
>         oformat.setStandalone(false);
> 
>         org.apache.xml.serialize.XMLSerializer serializer =
>             new org.apache.xml.serialize.XMLSerializer(oformat);
>         serializer.setOutputCharStream(new java.io.PrintWriter(System.out));
>         serializer.serialize(myDoc);
>     }
>   }

-- 
----------------------------------------------------------------------
Assaf Arkin                                           www.exoffice.com
CTO, Exoffice Technologies, Inc.                        www.exolab.org

Reply via email to