You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Jason Rizer <ja...@yahoo.com> on 2001/04/19 05:05:07 UTC
How to handle missing DTD
Hello. I've inherited some code which uses XML to
persist the state of various objects. I had
everything working fine until I realized that at some
time in the past, the program used a DTD. The problem
is that certain legacy clients may try to parse XML
which contains the DOCTYPE Element. When I test
against this XML, the following exception is thrown:
org.xml.sax.SAXParseException: File
"file:/C:/Project1/APMML.dtd" not
found.
at
org/apache/xerces/framework/XMLParser.reportError
(XMLParser.java:1324)
at
org/apache/xerces/framework/XMLParser.startReadingFromExternalEntity
(XMLParser.java:2673)
at
org/apache/xerces/framework/XMLParser.startReadingFromExternalSubset
(XMLParser.java:2467)
at
org/apache/xerces/validators/dtd/DTDValidator.startReadingFromExternalSubset
(DTDValidator.java:1671)
at
org/apache/xerces/framework/XMLDTDScanner.scanDoctypeDecl
(XMLDTDScanner.java:1113)
at
org/apache/xerces/validators/dtd/DTDValidator.scanDoctypeDecl
(DTDValidator.java:450)
at
org/apache/xerces/framework/XMLParser.scanDoctypeDecl
(XMLParser.java:2103)
at
org/apache/xerces/framework/XMLDocumentScanner$PrologDispatcher.dispatch
(XMLDocumentScanner.java:877)
at
org/apache/xerces/framework/XMLDocumentScanner.parseSome
(XMLDocumentScanner.java:381)
at org/apache/xerces/framework/XMLParser.parse
(XMLParser.java:1210)
at Class1.main (Class1.java:90)
I realize I could dummy up an "apmml.dtd" dtd and ship
it, but I really want to avoid having any dependency
on a dtd of any sort being in any particular location.
The only other solution I've seen is to inherit from
DOMParser and override startReadingFromExternalSubset(
) and stopReadingFromExternalSubset( ) with null
implementations, but there has to be a cleaner way to
do this. I would think that there is some way to tell
the parser to ignore the DTD specifier, but I can't
figure it out. Anyone know how I can get around this
problem? Any help would be greatly appreciated!
Blue Skies
-Jason
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: How to handle missing DTD
Posted by Milind Gadre <mi...@ecplatforms.com>.
Jason, attached is a sample EntityResolver class that you should
register with your parser *before* calling the parse method. For good
measure, the file also contains a sample ErrorHandler that will respond
to validation errors. Again, register this *prior* to calling parse.
Hope this helps.
Regards...
Milind Gadre
ecPlatforms, Inc
901 Mariner's Island Blvd, Suite 565
San Mateo, CA 94404
C: 510-919-0596
F: 815-352-0779
milind@ecplatforms.com
----- Original Message -----
From: "Jason Rizer" <ja...@yahoo.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, April 18, 2001 8:05 PM
Subject: How to handle missing DTD
> Hello. I've inherited some code which uses XML to
> persist the state of various objects. I had
> everything working fine until I realized that at some
> time in the past, the program used a DTD. The problem
> is that certain legacy clients may try to parse XML
> which contains the DOCTYPE Element. When I test
> against this XML, the following exception is thrown:
>
> org.xml.sax.SAXParseException: File
> "file:/C:/Project1/APMML.dtd" not
> found.
> at
> org/apache/xerces/framework/XMLParser.reportError
> (XMLParser.java:1324)
> at
> org/apache/xerces/framework/XMLParser.startReadingFromExternalEntity
> (XMLParser.java:2673)
> at
> org/apache/xerces/framework/XMLParser.startReadingFromExternalSubset
> (XMLParser.java:2467)
> at
>
org/apache/xerces/validators/dtd/DTDValidator.startReadingFromExternalSu
bset
>
> (DTDValidator.java:1671)
> at
> org/apache/xerces/framework/XMLDTDScanner.scanDoctypeDecl
> (XMLDTDScanner.java:1113)
> at
> org/apache/xerces/validators/dtd/DTDValidator.scanDoctypeDecl
> (DTDValidator.java:450)
> at
> org/apache/xerces/framework/XMLParser.scanDoctypeDecl
> (XMLParser.java:2103)
> at
>
org/apache/xerces/framework/XMLDocumentScanner$PrologDispatcher.dispatch
> (XMLDocumentScanner.java:877)
> at
> org/apache/xerces/framework/XMLDocumentScanner.parseSome
> (XMLDocumentScanner.java:381)
> at org/apache/xerces/framework/XMLParser.parse
> (XMLParser.java:1210)
> at Class1.main (Class1.java:90)
>
>
> I realize I could dummy up an "apmml.dtd" dtd and ship
> it, but I really want to avoid having any dependency
> on a dtd of any sort being in any particular location.
> The only other solution I've seen is to inherit from
> DOMParser and override startReadingFromExternalSubset(
> ) and stopReadingFromExternalSubset( ) with null
> implementations, but there has to be a cleaner way to
> do this. I would think that there is some way to tell
> the parser to ignore the DTD specifier, but I can't
> figure it out. Anyone know how I can get around this
> problem? Any help would be greatly appreciated!
>
> Blue Skies
> -Jason
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>