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 John Butler <jo...@gmail.com> on 2012/08/22 16:25:19 UTC
Validate XML with loading schemas at runtime, failure depending on
schema order
I have posted this question on Stack Overflow here:
http://stackoverflow.com/questions/11852311/validate-xml-with-loading-schemas-at-runtime-failure-depending-on-schema-order
I am trying to do xml validation. I am being given a list of schemas at
run-time (possibly wrapped in a jar). Validation passes or failes based on
the order in which I provide the schemas to the SchemaFactory.
Here is what I am doing:
private void validateXml(String xml, List<URI> schemas){
Source[] source = new StreamSource[schemas.size()];
int i=0;
for (URI f : schemas){
source[i++] = new StreamSource(f.openStream());
}
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NA_URI);
sf.setResourceResolver(new MyClassPathResourceResolver());
Schema schema = schemaFactory.newSchema(source);
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new
ByteArrayInputStream(xml.getBytes()));
again, this fails if the passed set of schema do not start with the schema
to which the root element of the xml referrs. Is there a fix to this or am
I doing something wrong?
Re: Validate XML with loading schemas at runtime, failure depending on
schema order
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi,
It's likely this problem [1] with the SchemaFactory. We're working on it.
Thanks.
[1] https://issues.apache.org/jira/browse/XERCESJ-1130
Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
dancerjohn@gmail.com wrote on 22/08/2012 10:25:19 AM:
> From: John Butler <jo...@gmail.com>
> To: j-users@xerces.apache.org,
> Date: 22/08/2012 10:41 AM
> Subject: Validate XML with loading schemas at runtime, failure
> depending on schema order
> Sent by: dancerjohn@gmail.com
>
> I have posted this question on Stack Overflow here:
>
> http://stackoverflow.com/questions/11852311/validate-xml-with-
> loading-schemas-at-runtime-failure-depending-on-schema-order
>
> I am trying to do xml validation. I am being given a list of schemas
> at run-time (possibly wrapped in a jar). Validation passes or failes
> based on the order in which I provide the schemas to the SchemaFactory.
>
> Here is what I am doing:
>
>
> private void validateXml(String xml, List<URI> schemas){
> Source[] source = new StreamSource[schemas.size()];
> int i=0;
> for (URI f : schemas){
> source[i++] = new StreamSource(f.openStream());
> }
>
> SchemaFactory sf = SchemaFactory.newInstance
> (XMLConstants.W3C_XML_SCHEMA_NA_URI);
> sf.setResourceResolver(new MyClassPathResourceResolver());
>
> Schema schema = schemaFactory.newSchema(source);
> Validator validator = schema.newValidator();
> validator.validate(new StreamSource(new
> ByteArrayInputStream(xml.getBytes()));
>
>
> again, this fails if the passed set of schema do not start with the
> schema to which the root element of the xml referrs. Is there a fix
> to this or am I doing something wrong?
>