According to the documentation at Sun documentation (http://java.sun.com/webservices/reference/tutorials/jaxp/html/sax.html), " When the application specifies the schema to use, it overrides any schema declaration in the document.". I've tried to setup a SAXParser on an HP-UX box using Xerces-J-2.9.1 which is JAXP1.2 compliant to use an external DTD rather than the one specified in the document.
What am I missing to get the Parser to ignore the internal DTD and use an external one? snippet - XML file has a DOCTYPE declaration: ====================================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mpd SYSTEM "mpboe03.dtd" [ <!ENTITY % isobox PUBLIC "-//W3C//ENTITIES Box and Line Drawing//EN//XML" "http://www.w3.org/2003/entities/2007/isobox.ent" > %isobox; snippet - code: ======================================================================= private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; try { //1. Create a SAXParserFactory object. SAXParserFactory spf = SAXParserFactory.newInstance(); //2. Set the namespace-aware and validating properties to true. spf.setNamespaceAware(true); spf.setValidating(true); // 3. Obtain a SAXParser object. SAXParser saxParser = spf.newSAXParser(); parser = saxParser.getXMLReader(); parser.setErrorHandler(this); // Turn on validation parser.setFeature("http://xml.org/sax/features/validation", true); //4. Set the properties for the schema language and schema source parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); parser.setProperty(JAXP_SCHEMA_SOURCE, myOwnDTD.getAbsolutePath()); //5. Parse the document. The parser must have access to an ErrorHandler object. parser.parse(file.getAbsolutePath()); // file is the xml file to parse }catch ... // all necessary exceptions Results: =================================================== Get an io.FileNotFoundException: The parser is looking for the DTD called out in the DOCTYPE declaration instead of using the one specified by the coder myOwnDTD.dtd. java.io.FileNotFoundException: mpboe03.dtd (No such file or directory (errno:2)) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at java.io.FileInputStream.<init>(FileInputStream.java:66) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161) at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source) at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source) at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source) at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at JavaXMLParse.parse(JavaXMLParse.java:103) at JavaXMLParse.main(JavaXMLParse.java:154) -- View this message in context: http://old.nabble.com/How-to-ignore-the-DTD-called-out-in-DOCTYPE-declaration-and-use-one-specified-by-the-user--tp26287359p26287359.html Sent from the Xerces - J - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org For additional commands, e-mail: j-users-h...@xerces.apache.org