xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Glavassevich <mrgla...@ca.ibm.com>
Subject Re: xml file with the wrong namespace passes validation
Date Mon, 03 Mar 2008 17:00:30 GMT
Hi Guillaume,

The JAXP 1.3 Validation API is better suited for what you want to do. If
you use a Schema [1] (created by the SchemaFactory [2]) for validation any
xsi: schema location hints in your document will be ignored.

Thanks.

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

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

Guillaume Laurent <guillaume.laurent@sophia.inria.fr> wrote on 03/03/2008
08:54:10 AM:

> Hi all,
>
> I'm currently scratching my head over the following problem. I have a
> validating parser for which the reference schema is specified through
code
> ( setAttribute(JAXP_SCHEMA_SOURCE, schema); ). The reference schema has a

> target namespace. The parser works fine, but surprisingly completelyfails
to
> detect an file which has both a different namespace and a reference to
its
> own schema.
>
> To sum up, given the following schema :
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>    targetNamespace="official/namespace"
> ...
>
> and the following code :
>
> setAttribute(JAXP_SCHEMA_SOURCE, "path/to/official/schema")
>
> Then a document like this :
>
> <foo xmlns="different/namespace"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="different/namespace path/to/different/schema.xsd">
>
> will be seen as valid by the parser.
>
> Is there a way to get the parser to reject the document, without
resorting to
> manuall checking the document's namespace ?
>
> Thanks,
>
> --
> Guillaume Laurent
> OASIS, Inria Sophia-Antipolis
> http://www-sop.inria.fr/oasis/
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message