Hi John,

<[EMAIL PROTECTED]> wrote on 08/15/2007 10:56:03 AM:

> Hi Michael,
> 
> The reason I started to look at resolver is because when I attempt to
> parse the XML document, 
> i.e. saxParser.getXMLReader().parse("C:/data/sample/shiporder.xml");
> 
> 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-external-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]

Reply via email to