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.  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.

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?

Thanks,
John

-----Original Message-----
From: Michael Glavassevich [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 14, 2007 5:36 PM
To: j-users@xerces.apache.org
Subject: RE: The markup declarations contained or pointed to by the
document type declaration must be well-formed.

Hi John,

I'm not sure why you need the resolver at all. In the code you posted,
you're compiling the schema using the JAXP SchemaFactory:

File schemaLocation = new File("file:///c:/data/sample/shiporder.xsd");
Schema schema = factory.newSchema(schemaLocation);

Presumably you're setting this Schema object [1] on the
SAXParserFactory, right? SAXParsers created from the SAXParserFactory
will use this schema for validation. You don't need to (and can't) tell
it where to find the schema during the parse. The validator already has
it and won't ask your resolver for any other sources.

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/parsers/SAXPar
serFactory.html#setSchema(javax.xml.validation.Schema)

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

<[EMAIL PROTECTED]> wrote on 08/14/2007 01:58:39 PM:

> Hello Michael,
> 
> Thank you for your response.  If I cannot replace the DTD specified in

> the DOCTYPE tag, then short of removing the tag all together, does 
> this mean there is no way for me to get XML validation to work (since 
> that does require notifying the parser about my schema XSD file).  Or 
> can I get this functionality by returning null from the resolver and 
> then assigning a schema to the parser/validator?
> 
> I tried to reduce my "schema" tag definition in my xsd to:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";> but I still 
> get the error.  I suppose my error is result of the resolver issue 
> rather than the namespace declaration.
> 
> John
> 
> 
> > 
> > I have an XML document which has a DOCTYPE tag referencing a DTD.
> > Instead I want to reference an XSD which specifies this document 
> > structure.  I use the XMLCatalogResolver to detect the publicId in 
> > the
> 
> > DOCTYPE and replace it with a URI pointing to the XSD.
> 
> You can't replace the DTD with a schema. Whatever you return from this

> call to the resolver needs to be a DTD (in other words must match [1] 
> the extSubset [2] production from the XML 1.0 specification) or null 
> if you want the parser to use its default resolution mechanism.
> 
> > I think this
> > part is working, however I get an error during the sax parsing:  
> > "The markup declarations contained or pointed to by the document 
> > type declaration must be well-formed."  I believe the XML is 
> > well-formed because if I omit the DOCTYPE tag from the XML document 
> > the parsing occurs without error.  The namespace in the XSD is 
> > "http://www.ncbi.nlm.nih.gov"; and I don't have any reference to 
> > namespace in the XML document.  Is this what the error is refering
to?
> 
> If your schema has a target namespace and your instance document 
> declares no namespaces you need to change one of them in order for 
> your document to be valid. Either add a namespace declaration to the 
> instance document or remove the target namespace from the schema
document.
> 
> <snip/>
> 
> > TIA,
> > John
> > 
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> 
> Thanks.
> 
> [1] http://www.w3.org/TR/2006/REC-xml-20060816/#ExtSubset
> [2] http://www.w3.org/TR/2006/REC-xml-20060816/#NT-extSubset
> 
> 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]

---------------------------------------------------------------------
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]

Reply via email to