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:24:21 UTC

Xerces - Feature not recognized for SchemaFactory but OK for Validator

I have posted this question on StackOverflow here:

http://stackoverflow.com/questions/12072867/xerces-feature-not-recognized-for-schemafactory-but-ok-for-validator

I am trying to set features for Xerces XML validation. I am having a hard
time finding / understanding which features are valid for the
`SchemaFactory` and for the `Validator`.

I have the following code:

    SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_US_URI);
    factory.setFeature("http://xml.org/sax/features/validation", true);

    Schema schema = factory.newSchema(mySchemaList);
    Validator validator = schema.newValidator;
    validator.setFeature("http://xml.org/sax/features/validation", true);

If I do the above I get:
`SAXNotRecognizedException: Feature 'http://xml.org/sax/features/validation`

However if I comment out the `setFeature` for the `SchemaFactory`, setting
the feature works for the `Validator`.

So questions:

1. Why can I set the feature on the `Validator` but not on the
`SchemaFactory`?
2. Where can I find documentation of which features are valid for
`Validator` and `SchemaFactory`?

FYI: the `SchemaFactory` I am getting is
`com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory`

# EDIT

Some of the other features I have tried to set with no success are:

`http://xml.org/sax/features/namespaces`

`http://xml.org/sax/features/namespace-prefixes`

Re: Xerces - Feature not recognized for SchemaFactory but OK for Validator

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

dancerjohn@gmail.com wrote on 22/08/2012 10:24:21 AM:

> I have posted this question on StackOverflow here:
> 
> http://stackoverflow.com/questions/12072867/xerces-feature-not-
> recognized-for-schemafactory-but-ok-for-validator
> 
> I am trying to set features for Xerces XML validation. I am having a
> hard time finding / understanding which features are valid for the 
> `SchemaFactory` and for the `Validator`.
> 
> I have the following code:
> 
>     SchemaFactory factory = SchemaFactory.newInstance
> (XMLConstants.W3C_XML_SCHEMA_US_URI);
>     factory.setFeature("http://xml.org/sax/features/validation", true);
> 
>     Schema schema = factory.newSchema(mySchemaList);
>     Validator validator = schema.newValidator;
>     validator.setFeature("http://xml.org/sax/features/validation", 
true);
> 
> If I do the above I get: 
> `SAXNotRecognizedException: Feature 
'http://xml.org/sax/features/validation`
> 
> However if I comment out the `setFeature` for the `SchemaFactory`, 
> setting the feature works for the `Validator`.
> 
> So questions:
> 
> 1. Why can I set the feature on the `Validator` but not on the 
> `SchemaFactory`?

The feature you're trying to set isn't relevant to the SchemaFactory, so 
it's not supported at that level of the API. The value of "
http://xml.org/sax/features/validation" is fixed to true on the validator. 
You cannot disable it. A Validator does validation. There's no reason to 
set that feature.

> 2. Where can I find documentation of which features are valid for 
> `Validator` and `SchemaFactory`?

Sorry, no one has got around to documenting all of that. Generally the 
ones that apply are those which relate directly to the behaviour of schema 
validation.

> FYI: the `SchemaFactory` I am getting is 
> `com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory`

com.sun.org.apache.xerces.internal.* isn't Apache Xerces. We have no 
influence over what Oracle / Sun support in their fork of the codebase.

> # EDIT
> 
> Some of the other features I have tried to set with no success are:
> 
> `http://xml.org/sax/features/namespaces`
> 
> `http://xml.org/sax/features/namespace-prefixes`

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