Re: DOCTYPE specified but DTD not available

Your question involves the specific behavior of one parser (my guess is
Xerces-J) and so it would be more appropriate to ask on the xerces-j-user
mailing list or another mailing list specific to the parser that you are
using.

The mechanics of creating a document object model from a XML document is
outside the scope of current Level 2 DOM specs, though it is in the scope of
the Level 3 Load and Save working draft.  However, that draft is only
experimentally implemented at this time.

There are a couple of issues with your sample, first the URL for the DTD
(C:\cs.dtd) is not a valid URL since backslashes are not allowed.  See
http://xml.apache.org/xerces2-j/faq-common.html#faq-1.  Some parsers are
forgiving when you use Windows UNC's, but that causes interoperability
problems.

Second, even if you aren't validating, some information from the DTD such as
entity definitions and default attributes are required to properly build the
DOM.  See http://xml.apache.org/xerces2-j/faq-write.html#faq-5

If you want, you could register an EntityResolver with the parser (assuming
Xerces-J or another DOM implementation layered on a SAX implementation)
which will get called to resolve the reference to the external DTD.  In the
resolver, you could return an empty stream that would make it look like the
file was empty which should allow parsing to continue.

Received on Saturday, 5 January 2002 14:47:42 UTC