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 Bengali Bengali <be...@gmail.com> on 2006/12/19 18:29:37 UTC

Resolving xml schemas includes for validation

Hi,

I 'd like to validate a XML message with external schemas but i need to
respect the following constraints:

- I can not modify XML schemas files. They use xml:include under the same
targetnamespace.
- it has to run on xerces 2.6.2
- XML schemas are included in Jar of wars so they should loaded with a
classloader.

So far, the Xerces 2.6.2 does not seem to follow includes. (and ignore them)

I tried to different solutions:

1) specifying a XML catalog with :

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
         prefer="public">
  <uri name="urn:Folder"
      uri="Folder.xsd"/>
  <uri name="urn:Folder"
      uri="basicTypes.xsd"/>
</catalog>

But it doesn't work because i guess i can not declare the same name in uri
elements of the catalog.

2) Setting the following JAXP parser property:

parser.setProperty(
                    "http://java.sun.com/xml/jaxp/properties/schemaSource",
                    new InputSource[]{......});

where the array of InputSource files contains all the schemas. But since
they declare the same target namespace i get the following error:

java.lang.IllegalArgumentException:  When using array of Objects as the
value of SCHEMA_SOURCE property , no two Schemas should share the same
targetNamespace.


3) Using xerces property
parser.setProperty("
http://apache.org/xml/properties/schema/external-schemaLocation",
"urn:Folder CreerDossier.xsd,urn:Folder basicTypes.xsd");
without success.

4)EntityResolver:

I still have the same issue because included schemas use the same
targetnamespace:
Which inputSource should I return ?

public InputSource resolveEntity (String publicId, String systemId)
   {

      }


So if you have any clue on how to solve this,
i'd be glad to know.

Luc

Re: Resolving xml schemas includes for validation

Posted by Bengali Bengali <be...@gmail.com>.
Even if I am not sure how to synthesize schemas at runtime
that's what i'll try to do. (wsdl4j seems to do such thing)

Thanks
Luc

On 12/20/06, Michael Glavassevich <mr...@ca.ibm.com> wrote:
>
> You could synthesize a schema document at runtime which includes each of
> the schema documents with the same target namespace and pass that to
> Xerces. This should work with Xerces 2.6.2 but would probably be easier to
> do with a more recent release which supports JAXP 1.3 and has far fewer
> schema bugs.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> "Bengali Bengali" <be...@gmail.com> wrote on 12/19/2006 12:29:37 PM:
>
> > Hi,
> >
> > I 'd like to validate a XML message with external schemas but i need
> > to respect the following constraints:
> >
> > - I can not modify XML schemas files. They use xml:include under the
> > same targetnamespace.
> > - it has to run on xerces 2.6.2
> > - XML schemas are included in Jar of wars so they should loaded with
> > a classloader.
> >
> > So far, the Xerces 2.6.2 does not seem to follow includes. (and ignore
> them)
> >
> > I tried to different solutions:
> >
> > 1) specifying a XML catalog with :
> >
> > <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
> >          prefer="public">
> >   <uri name="urn:Folder"
> >       uri=" Folder.xsd"/>
> >   <uri name="urn:Folder"
> >       uri="basicTypes.xsd"/>
> > </catalog>
> >
> > But it doesn't work because i guess i can not declare the same name
> > in uri elements of the catalog.
> >
> > 2) Setting the following JAXP parser property:
> >
> > parser.setProperty(
> >                     "
> http://java.sun.com/xml/jaxp/properties/schemaSource",
> >                     new InputSource[]{......});
> >
> > where the array of InputSource files contains all the schemas. But
> > since they declare the same target namespace i get the following error:
> >
> > java.lang.IllegalArgumentException:  When using array of Objects as
> > the value of SCHEMA_SOURCE property , no two Schemas should share
> > the same targetNamespace.
> >
> >
> > 3) Using xerces property
> > parser.setProperty ("http://apache.
> > org/xml/properties/schema/external-schemaLocation", "urn:Folder
> > CreerDossier.xsd,urn:Folder basicTypes.xsd");
> > without success.
> >
> > 4)EntityResolver:
> >
> > I still have the same issue because included schemas use the same
> > targetnamespace:
> > Which inputSource should I return ?
> > public InputSource resolveEntity (String publicId, String systemId)
> >
> >    {
> >       }
> >
> >
> > So if you have any clue on how to solve this,
> > i'd be glad to know.
> >
> > Luc
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>

Re: Resolving xml schemas includes for validation

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
You could synthesize a schema document at runtime which includes each of 
the schema documents with the same target namespace and pass that to 
Xerces. This should work with Xerces 2.6.2 but would probably be easier to 
do with a more recent release which supports JAXP 1.3 and has far fewer 
schema bugs.

Thanks.

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

"Bengali Bengali" <be...@gmail.com> wrote on 12/19/2006 12:29:37 PM:

> Hi,
> 
> I 'd like to validate a XML message with external schemas but i need
> to respect the following constraints:
> 
> - I can not modify XML schemas files. They use xml:include under the
> same targetnamespace.
> - it has to run on xerces 2.6.2
> - XML schemas are included in Jar of wars so they should loaded with
> a classloader.
> 
> So far, the Xerces 2.6.2 does not seem to follow includes. (and ignore 
them)
> 
> I tried to different solutions: 
> 
> 1) specifying a XML catalog with :
> 
> <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
>          prefer="public">
>   <uri name="urn:Folder"
>       uri=" Folder.xsd"/> 
>   <uri name="urn:Folder"
>       uri="basicTypes.xsd"/> 
> </catalog>
> 
> But it doesn't work because i guess i can not declare the same name 
> in uri elements of the catalog.
> 
> 2) Setting the following JAXP parser property:
> 
> parser.setProperty(
>                     " 
http://java.sun.com/xml/jaxp/properties/schemaSource",
>                     new InputSource[]{......});
> 
> where the array of InputSource files contains all the schemas. But 
> since they declare the same target namespace i get the following error: 
> 
> java.lang.IllegalArgumentException:  When using array of Objects as 
> the value of SCHEMA_SOURCE property , no two Schemas should share 
> the same targetNamespace. 
> 
> 
> 3) Using xerces property
> parser.setProperty ("http://apache.
> org/xml/properties/schema/external-schemaLocation", "urn:Folder 
> CreerDossier.xsd,urn:Folder basicTypes.xsd"); 
> without success.
> 
> 4)EntityResolver:
> 
> I still have the same issue because included schemas use the same 
> targetnamespace:
> Which inputSource should I return ?
> public InputSource resolveEntity (String publicId, String systemId)
> 
>    {
>       }
> 
> 
> So if you have any clue on how to solve this,
> i'd be glad to know.
> 
> Luc


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