Will, When I try this, I get an error that says:
javax.xml.parsers.ParserConfigurationException: jaxp_feature_not_supported: Feature "http://xml.org/sax/features/use-entity-resolver2" is not supported. What am I doing wrong? Mike _____ From: Will Holcomb [mailto:[EMAIL PROTECTED] Sent: Sunday, February 25, 2007 9:47 AM To: j-users@xerces.apache.org; [EMAIL PROTECTED] Subject: Re: Specifying a DTD file when parsing XML files that don't contain !DOCTYPE lines 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> 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; } }