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:39:42 GMT
On Thu, 2005-02-17 at 12:25 -0500, Jason Vinson wrote:
> For the benefit of anyone who is looking for the answers to these
> questions, here's what i've found.  Please correct any glaring errors
> if you see them.
> 
> 1.) AFAIK, XSD is supported in the digester if you use a non-Xerces
> parser (i.e. Crimson)

No, it's supported no matter what parser you use, once it's enabled.
It's just enabling schema validation that may be a little tricky.

Note that crimson is an old, obsolete xml parser that was bundled with
Sun's JAXP downloads for java 1.3 and earlier. I would not recommend its
use for *any* purpose. When using sun java < 1.3, just download a recent
release of xerces or any other xml parser. Sun java 1.4 and later comes
bundled with xerces.

> 
> 2.) In order to setup validation with crimson in the digester, you
> have to do something similar to the following:
> 
> ~        SAXParserFactoryImpl crimsonFactory = new SAXParserFactoryImpl();
> ~        crimsonFactory.setValidating(true);
> ~        URL url =
> Digester.class.getClassLoader().getResource("myFunSchema.xsd");
> ~        String schemaPath = url.toString();
> 
> ~        Digester digester = new Digester(crimsonFactory.newSAXParser());
> ~        digester.setSchema(schemaPath);


The Digester.setSchema method will have no effect at all if you use the
digester constructor variant that takes a parser as a parameter. So I
don't think the above code sets the schema path at all.

Also, I would be very surprised if the parser you are instantiating is
really crimson. As noted above, crimson is old and obsolete.

Re the code above to create the parser: if you want to create your own
parser, then this is indeed the way to do it. However this code is
exactly what will happen if you just let digester create the parser
anyway - except that when Digester creates the parser, the
Digester.setSchema and Digester.setValidating methods are not ignored.

> ~        digester.setErrorHandler(
> ~                  new ErrorHandler() {
> ~                      public void error(SAXParseException exception)
> throws SAXException {
> ~                          throw new SAXExceptionSubclass("Error
> validating XML - " + exception.getMessage());
> ~                      }
> ~                      public void fatalError(SAXParseException
> exception) throws SAXException {
> ~                          throw new SAXExceptionSubclass("Fatal Error
> validating XML - " + exception.getMessage());
> ~                      }
> ~                      public void warning(SAXParseException exception)
> throws SAXException {
> ~                          throw new SAXExceptionSubclass("Warning
> validating XML - " + exception.getMessage());
> ~                      }
> ~                  }
> ~                 );

Yep. You definitely need to do this, otherwise validation errors are
logged but not reported. There must be some historical reason for this;
it predates my involvement with Digester.


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