users@jaxb.java.net

Re: JAXB Marshal Not specifying the DTD in generated XML

From: Glenn Kidd <glennkidd_at_mail.com>
Date: Mon, 19 May 2003 02:18:05 -0600

>> I am trying to implement JAXB. But when I marshal the Java Content Tree,
>> the resulting output does not have the DTD (<!DOCTYPE CIN PUBLIC
>> "-//Interleaf//DTD CIN//EN" "cin.dtd" [ ]) that this document has to be
>> validated against. Please let me know if I have to do anything special
>> in order to achieve this result.
>
>Probably the easiest way to do is for you to look for XMLWriter
>implementation that supports DOCTYPE. I'm not 100% sure but it seems
>like Apache XMLSerializer [1] supports this.
>
>XMLSerializer can receive SAX events and produce the equivalent textual XML
>representation, you then configure XMLSerialiier to produce the desired
>DOCTYPE declaration, then marshal JAXB content tree into XMLSerializer
>by using the marshal(Object,ContentHandler) method.

This has been very useful information. So after you have an XMLSerializer and an XML document ready to serialized, how do you get the DTD into the serialized output? For instance, given the code below:


JAXBContext outJAXBContext = JAXBContext.newInstance(...);
OutputStream out = new OutputStream();
OutputFormat of = new OutputFormat(...);
XMLSerializer xmlSer = new XMLSerializer(out, of);
Marshaller marshaller = outJAXBContext.createMarshaller();
marshaller.marshal(obj, xmlSer);


How and where do I get the DTD into the serialized output? Any help would be greatly appreciated. Thanks in advance.