One more note about a bug I found in this code. It only works once. When you
parse a second document, you get an exception because the FileReader for the
DTD has already been closed.

Will Holcomb

On 2/25/07, Will Holcomb <[EMAIL PROTECTED]> wrote:

I happened to send a message to this list asking this exact question
> earlier this week. I figure I'll pass on the kindness someone showed me and
> answer it this time/ (Perhaps this should go in the FAQ because it isn't
> really intuitive.)
>
> final static String ENTITY_RESOLVER_2_ID = 
"http://xml.org/sax/features/use-entity-resolver2";;
>
> DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
> dbFactory.setFeature(ENTITY_RESOLVER_2_ID, true);
> DocumentBuilder builder = dbFactory.newDocumentBuilder();
> builder.setEntityResolver(new DTDEntityResolver(new
> FileReader(dtdFilename)));
>
> public class DTDEntityResolver implements EntityResolver2 {
>   InputSource input;
>   public DTDEntityResolver(Reader dtd) { input = new InputSource(dtd); }
>   public InputSource getExternalSubset(String name, String baseURI)

    throws SAXException { return input; }
>   public InputSource resolveEntity(String publicId, String systemId) {return 
null;}
>   public InputSource resolveEntity(String name, String publicId, String
> baseURI, String systemId)
>         throws SAXException { return null; }
> }
>

Reply via email to