users@jaxb.java.net

Re: Unmarshalling XML with a doctype

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Fri, 16 May 2003 13:45:06 -0700

> I am trying to unmarshall an XML document that has a doctype specified
> but JAXB does not seem to like it. If I remove the doctype declaration
> it works fine. The problem is that the application I am writing is a
> replacement for a pre-existing one and the incoming XML documents it
> handles all have the doctype declaration. Is there a way to get JAXB to
> ignore the doctype declaration? Thanks in advance.

Technically, it's an XML parser's problem, not that of JAXB.

Now bigger question is, what do you mean by "ignoring DTD"?

Pretending that you didn't see any DOCTYPE declaration is in violation
of XML1.0, though with a certain parser like Xerces, you can do this by
using its property.

If you choose to do this, you have to create a XMLReader, and configure
it by yourself, and pass it to JAXB Unmarshaller.


Another way out is to use the setEntityResolver method to set an
EntityResolver. Whenever a DOCTYPE declaration is hit, XML parser will
ask your EntityResolver to resolve the DTD into a byte stream. If the
DOCTYPE declaration contains a link to an unreachable location, you can
use this mechanism to redirect the parser to your local copy.


Or depending on what you mean by "JAXB doesn't like it", maybe it's a
bug of the JAXB RI.


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com