Hello, I am trying to set up a SAXParser to parse and validate any input XML file that contains both DOCTYPE and no DOCTYPE definitions using a DTD that I specify. After combing through the mailing list archives, I was able to get it working (thanks to posting *9e9da3a00702250947n1571e875g92fbe3aa030b23c7 () mail ! gmail ! com*<http://marc.info/?i=9e9da3a00702250947n1571e875g92fbe3aa030b23c7%20()%20mail%20!%20gmail%20!%20com>).
However, the posting also warned about it only works for one document and will not work for subsequent documents. I was wondering if any workaround or fix has been found to resolve that issue. Thanks in advance. Nida Here is the thread from that old posting for reference: *List: **xerces-j-dev* <http://marc.info/?l=xerces-j-dev&r=1&w=2> *Subject: **Re: Specifying a DTD file when parsing XML files that don't contain !DOCTYPE lines* <http://marc.info/?t=117242134000001&r=1&w=2> *From: **"Will Holcomb" <wholcomb () gmail ! com>*<http://marc.info/?a=114966701700007&r=1&w=2> *Date: **2007-02-25 17:47:29*<http://marc.info/?l=xerces-j-dev&r=1&w=2&b=200702> *Message-ID: **9e9da3a00702250947n1571e875g92fbe3aa030b23c7 () mail ! gmail ! com*<http://marc.info/?i=9e9da3a00702250947n1571e875g92fbe3aa030b23c7%20()%20mail%20!%20gmail%20!%20com> *[**Download message RAW*<http://marc.info/?l=xerces-j-dev&m=117242568113713&q=raw> *]* 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; } > > } > >
