commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [Digester] XSD Support?
Date Thu, 17 Feb 2005 23:22:10 GMT
On Thu, 2005-02-17 at 11:29 -0500, Jason Vinson wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> After reading some docs around the web, i found this:
> 
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg31474.html
> 
> And then found some other docs (not sure of the age) that mention
> Xerces having limited XML Schema support.  So I guess my questions are
> 1.) Do any of you use XSD's with your digesters, and 2.) how can i use
> something other than Xerces for my content handler in the digester?

It should be quite possible to do schema validation when using Digester.

(a) selecting a parser for digester to use:

Digester can use an xml parser you explicitly provide:
  // somehow instantiate and configure the parser you want
  Digester d = new Digester(myparser);

Alternatively, you can allow Digester to create the xml parser instance
(using the default java discovery mechanism to find it), then tweak its
settings:
  Digester d = new Digester();
  XMLReader reader = d.getXMLReader();
  reader.setFeature(....);
  reader.setProperty(...);
  etc

If you let Digester create the parser, then you can control which
implementation it finds by using the standard JDK mechanisms. See the
javadoc for SAXParserFactory.newInstance() for more information.

The default parser in java 1.4 is org.apache.xerces. The default parser
in java 1.5 is com.sun.org.apache.xerces, ie still xerces but with the
package name tweaked slightly to avoid problems that plagued 1.4 when
attempting to use a newer version of xerces. You mention the "crimson"
parser in another email; I believe this is the default only if you
download an old JAXP implementation for jdks <= 1.3.

Note also that using an "upgraded" version of xerces with java 1.4 is
very difficult; core classes in the java runtime override classes in the
classpath - and they bundled o.a.xerces in the runtime! There are ways
around this - see the xerces site, or google.

(b) enabling schema validation on the parser:

The W3C standards mandate a couple of features/properties that all
parsers must recognise. But unfortunately there are many useful features
that are *not* standardised, so you need to know what actual parser
implementation is being used in order to configure those. And sadly
enabling schema validation is one of those.

The email you refer provides an API for configuring some
commonly-used-but-not-standardised parser features, by having a set of
per-parser-implementation modules that can map the calls onto the
parser-specific property or feature. This code was committed to
Digester, and is present in the 1.6 release, in the o.a.c.d.parsers
package. Of course this only works if the actual parser being used by
digester is one with support code present in the o.a.c.d.parsers
package.

In an separate email, you wrote:
On Thu, 2005-02-17 at 10:24 -0500, Jason Vinson wrote:
> I am reworking a digester module in a project to use an XSD for
> validation, and I am getting an interesting exception from the
> org.apache.commons.digester.parser.XercesParser class.  In the
> configureXerces method on the line that says:
> 
> factory.setFeature(XERCES_DYNAMIC, true);
> 
> i get the following:
> 
> org.xml.sax.SAXNotRecognizedException: Feature:

I don't know why that is happening. I presume you're calling the
Digester.setSchema method? That method calls into the o.a.c.d.parsers
code, which auto-detects what concrete parser type you have (xerces it
would appear) then performs the appropriate parser-specific setup to
enable schema validation. It looks to me like either you have some odd
parser in your path that is being detected as xerces when it isn't, or
you have a very old or new version of xerces that doesn't support the
feature "http://apache.org/xml/features/validation/dynamic", or uses
some other name for it.

I can't help you with any problems in the o.a.c.d.parser package. You
may wish to contact Jean-Francois Arcand who wrote that code. 

But personally I wouldn't bother with calling Digester.setSchema anyway;
just set up the parser to do schema validation manually (ie *not*
through the digester APIs). See section (a) above for ways of doing
that. Of course you'll then have to include parser-specific code in your
application - thank the W3C and Sun for not providing a standard way to
enable schema validation!

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message