I'm not surprised. Your EntityResolver is unconditionally returning the same InputSource regardless of the parameters passed to resolveEntity(). Looks like your EntityResolver would be called at least twice; once for the external DTD ("?mpboe03.dtd") and once for the "isobox" parameter entity ( "http://www.w3.org/2003/entities/2007/isobox.ent"). You should examine the systemId / publicId in your decision making of what to return from the method.
Thanks. Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: mrgla...@ca.ibm.com E-mail: mrgla...@apache.org DeWayne <dewayne.c.dantz...@boeing.com> wrote on 11/10/2009 08:39:04 PM: > Ok, I create an entity resolver to specify the external DTD. However, I'm > getting many parse errors of the kind > > Error: Parsing - Element type "task-description" must not be declared more > than once. > Error: Parsing - Element type "cmr-type" must not be declared more than > once. > Error: Parsing - Element type "related-mrbs" must not be declared more than > once. > Error: Parsing - Element type "related-mrb" must not be declared more than > once. > Error: Parsing - Element type "task-cat" must not be declared more than > once. > Error: Parsing - Element type "cmr-intervals" must not be declared more than > once. > Error: Parsing - Element type "cmr-interval" must not be declared more than > once. > Error: Parsing - Element type "precluded-tasks" must not be declared more > than once. > Error: Parsing - Element type "precluded-task" must not be declared more > than once. > Error: Parsing - Element type "precluded-struct-task" must not be declared > more than once. > Error: Parsing - Element type "precluded-struct-tasks" must not be declared > more than once. > Error: Parsing - Element type "precluded-sys-task" must not be declared more > than once. > > This is odd because I placed the same DTD in the XML file's DOCTYPE > declaration and parse the file w/o using an entity resolver and it parses > without errors. What am I doing wrong with my entity resovler or is it not > setting a specific DTD feature on the Parser? > > snippet - code of entity resolver > ============================================== > public InputSource resolveEntity(String publicId, String systemId) > throws SAXException, IOException > { > if(_MyOwnSystemId != null) > { > InputSource is = new InputSource(_MyOwnSystemId ); > return is; > } > else// use the default behavior > { > return null; > } > } > > ======================================================================== > > Michael Glavassevich-3 wrote: > > > > Hi, > > > > The JAXP 1.2 schema properties are only relevant to XML Schema validation. > > They have nothing to do with loading DTDs. Try using an EntityResolver [1] > > instead. > > > > Thanks. > > > > [1] > > http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/ > EntityResolver.html > > > > Michael Glavassevich > > XML Parser Development > > IBM Toronto Lab > > E-mail: mrgla...@ca.ibm.com > > E-mail: mrgla...@apache.org > > > > DeWayne <dewayne.c.dantz...@boeing.com> wrote on 11/10/2009 01:06:54 PM: > > > >> 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 > > > > -- > 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--tp26287359p26294433.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