Hi Michael, Thank you for pointing out the "load-external-dtd" feature. That did the trick at least for my original problem with the DOCTYPE handling.
I tried as you suggested by setting: spf.setNamespaceAware(true); // the default is false, but I think you're setting it to true spf.setValidating(false); Actually, I was setting setNamespaceAware to true before, but I had been setting setValidating incorrectly. Now I'm still catching this error: cvc-elt.1: Cannot find the declaration of element 'shiporder' If I change my schema definition from: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.ncbi.nlm.nih.gov" targetNamespace="http://www.ncbi.nlm.nih.gov" elementFormDefault="qualified" attributeFormDefault="unqualified"> And remove the targetNamespace: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.ncbi.nlm.nih.gov" elementFormDefault="qualified" attributeFormDefault="unqualified"> Then the parse succeeds. Is there something in my code that can handle the targetNamespace? My XML document does not have any namespace qualification. I also tried to set elementFormDefault to "unqualified" in the schema definition but that didn't do anything. Thanks, John > I get an exception: > > C:\data\sample\NCBI_Entrezgene.dtd (The system cannot find the file > specified) > > This is the file described in the DOCTYPE tag in the XML document. I > was hoping that I could use the resolver to ignore this tag or point > it to a different resource which does exist (my XSD in this case). > Correct me if I'm wrong, but I thought that the purpose of the > resolver was to redirect the parser to another resource if it could > not find the one specified in the document. Yes, but it needs to be another resource of the same type. You can't return a DTD in place of a schema either. > But as you said previously, it seems I can only redirect a DTD to > another DTD. If there is any other way you know of ignoring this > DOCTYPE then I'd like to know. An empty document (one with zero characters in it) is a well-formed external DTD. You could try returning that from the resolver or just turn off the "load-external-dtd" feature [1] and the parser will ignore the external DTD completely. > As for the schema, I have set the schema in the SAXParserFactory: > > SchemaFactory factory = SchemaFactory.newInstance(W3C_XML_SCHEMA); > File schemaLocation = new File("/data/sample/shiporder.xsd"); > Schema schema = factory.newSchema(schemaLocation); > SAXParserFactory spf = SAXParserFactory.newInstance(); > spf.setSchema(schema); > > If I manually delete the DOCTYPE tag from the XML document (not my > ideal way of dealing with the above issue), I get another error: > Error: URI=file:///C:/data/sample/shiporder.xml Line=2: Document is > invalid: no grammar found. > Error: URI=file:///C:/data/sample/shiporder.xml Line=2: Document root > element "shiporder", must match DOCTYPE root "null". > Error: URI=file:///C:/data/sample/shiporder.xml Line=2: cvc-elt.1: > Cannot find the declaration of element 'shiporder'. > > So, it seems its still insisting on or relying on a DOCTYPE > declaration of some sort? Seems like you have DTD validation enabled and namespace-awareness off. You should be setting the SAXParserFactory up like: SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setSchema(schema); // always turn this on; XML schema validation requires namespace support spf.setNamespaceAware(true); // the default is false, but I think you're setting it to true spf.setValidating(false); > Thanks, > John [1] http://xerces.apache.org/xerces2-j/features.html#nonvalidating.load-exte rnal-dtd Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]