You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Simon Bøggild <si...@gmail.com> on 2007/11/20 11:05:25 UTC

SchemaFactory - check of non-valid imports

Hi,

When using SchemaFactory to load and check a schema file, it seems to
ignore if the schema imports other schemas that doesn't exist. If for
instance there's a typo in the import line in the schema: <import
schemaLocation="file.xsdd" namespace=...>, where the "file.xsdd"
should have been written as "file.xsd", this seems to be ignored.
Sure, it generates an error when trying to process elements in the
schema deriving from the (wrongly spelled) imported schema file, but
it's not the actual misspelling in the import that raises the error.
Is there an option to set somewhere that causes SchemaFactory to throw
an exception if the imported schema does not exist? or is it necessary
to write your own LSResourceResolver implementation that manually
checks if the imported files exist?

Thanks,
Simon

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: SchemaFactory - check of non-valid imports

Posted by Simon Bøggild <si...@gmail.com>.
Hi Michael,

You were right about that, thanks :-)

Simon

On Nov 21, 2007 5:15 AM, Michael Glavassevich <mr...@ca.ibm.com> wrote:
> Hi Simon,
>
> Failure to resolve an import [1] is not an error however Xerces does report
> a warning to let the user know that it failed. I suspect that you haven't
> registered a an ErrorHandler with the SchemaFactory. By default (see
> DraconianErrorHandler) [2] it will silently ignore warnings.
>
> If you write your own ErrorHandler and register it with the SchemaFactory
> you should get a warning which looks like:
>
> schema_reference.4: Failed to read schema document
> 'file:///C:/bar/foo.xsd', because 1) could not find the document; 2) the
> document could not be read; 3) the root element of the document is not
> <xsd:schema>.
>
> If you want this warning to be fatal throw an exception from your
> ErrorHandler.
>
> Thanks.
>
> [1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#src-import
> [2]
> http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html#setErrorHandler(org.xml.sax.ErrorHandler)
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> "Simon Bøggild" <si...@gmail.com> wrote on 11/20/2007 05:05:25 AM:
>
>
> > Hi,
> >
> > When using SchemaFactory to load and check a schema file, it seems to
> > ignore if the schema imports other schemas that doesn't exist. If for
> > instance there's a typo in the import line in the schema: <import
> > schemaLocation="file.xsdd" namespace=...>, where the "file.xsdd"
> > should have been written as "file.xsd", this seems to be ignored.
> > Sure, it generates an error when trying to process elements in the
> > schema deriving from the (wrongly spelled) imported schema file, but
> > it's not the actual misspelling in the import that raises the error.
> > Is there an option to set somewhere that causes SchemaFactory to throw
> > an exception if the imported schema does not exist? or is it necessary
> > to write your own LSResourceResolver implementation that manually
> > checks if the imported files exist?
> >
> > Thanks,
> > Simon
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: SchemaFactory - check of non-valid imports

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Simon,

Failure to resolve an import [1] is not an error however Xerces does report
a warning to let the user know that it failed. I suspect that you haven't
registered a an ErrorHandler with the SchemaFactory. By default (see
DraconianErrorHandler) [2] it will silently ignore warnings.

If you write your own ErrorHandler and register it with the SchemaFactory
you should get a warning which looks like:

schema_reference.4: Failed to read schema document
'file:///C:/bar/foo.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.

If you want this warning to be fatal throw an exception from your
ErrorHandler.

Thanks.

[1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#src-import
[2]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html#setErrorHandler(org.xml.sax.ErrorHandler)

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Simon Bøggild" <si...@gmail.com> wrote on 11/20/2007 05:05:25 AM:

> Hi,
>
> When using SchemaFactory to load and check a schema file, it seems to
> ignore if the schema imports other schemas that doesn't exist. If for
> instance there's a typo in the import line in the schema: <import
> schemaLocation="file.xsdd" namespace=...>, where the "file.xsdd"
> should have been written as "file.xsd", this seems to be ignored.
> Sure, it generates an error when trying to process elements in the
> schema deriving from the (wrongly spelled) imported schema file, but
> it's not the actual misspelling in the import that raises the error.
> Is there an option to set somewhere that causes SchemaFactory to throw
> an exception if the imported schema does not exist? or is it necessary
> to write your own LSResourceResolver implementation that manually
> checks if the imported files exist?
>
> Thanks,
> Simon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org