From: <[EMAIL PROTECTED]>
> Hi,
>
> I am trying to parse an xml file in my application, where the DOCTYPE
> declaration points to a DTD which does not exist. The SAXReader therefor
throws
> Exceptions at me, being annoyed by this. How can I prevent this and let
the
> SAXReader parse the document without checking for the existence of the DTD
file?
>
> Thanks,
> Olav
A common way around this is to implement a SAX EntityResolver to load the
DTD from somewhere else. e.g. you could include the DTD in your JAR with
your java code and load it from there.
EntityResolver resolver = new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) {
if ( publicId.equals( "-//Acme//DTD Foo 1.2//EN" ) ) {
InputStream in = getClass().getResourceAsStream(
"com/acme/foo.dtd" );
return new InputSource( in );
}
return null;
}
};
SAXReader reader = new SAXReader();
reader.setEntityResolver( resolver );
Document doc = reader.parse( "foo.xml" );
James
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user