Project

Profile

Help

Using Xerces Validating Parser with 8.4

Added by Anonymous about 19 years ago

Legacy ID: #3117564 Legacy Poster: W. Eliot Kimber (drmacro)

This should be easy to do and I'm pretty sure I've done it before, but I can't for the life of me figure out how to use a schema-aware XML parser (i.e., from the Xerces 2.6.2 package) with Saxon 8.4B. It should be as simple as specifying the right class on the -x parameter to Saxon but I can't figure out what class from which Xerces-provided library to use. I am using Java 1.4. I have downloaded the JAXP libraries and put them in my class path. Or do I have to write my own wrapper class to instantiate the parser? Thanks, Eliot


Replies (2)

RE: Using Xerces Validating Parser with 8.4 - Added by Anonymous about 19 years ago

Legacy ID: #3117609 Legacy Poster: Michael Kay (mhkay)

As a far as I'm aware there's no class representing a validating-Xerces-parser as such, and therefore no way to invoke this as your parser using the -x option. You have to instantiate the parser and then set properties saying you want it to do schema validation. If you want to invoke this from the Saxon command line I think it does indeed mean implementing an XMLReader that wraps the Xerces parser. There might be a way of doing it using Java system properties, but I can't quite think how: if -x isn't specified then Saxon uses the JAXP ParserFactory to find a parser, which is driven by the jaxp.xml.parser.SAXParserFactory system property, but again that only gets you to the class, not to its properties/features. Michael Kay

RE: Using Xerces Validating Parser with 8.4 - Added by Anonymous about 19 years ago

Legacy ID: #3121318 Legacy Poster: W. Eliot Kimber (drmacro)

OK, after much pointless struggle and dead ends, I finally figured out that it just requires a trivial subclass of the Xerces SAXParser that you then specify on the -x parameter. Here's my class: import org.apache.xerces.parsers.SAXParser; public class ValidatingParser extends SAXParser { public ValidatingParser() throws Throwable { super(); this.setFeature("http://xml.org/sax/features/validation", true); this.setFeature("http://apache.org/xml/features/validation/dynamic", true); this.setFeature("http://apache.org/xml/features/validation/schema", true); this.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", true); } What doesn't make sense to me is why, at least as far as I can tell, you can't set these features as system properties--that would make the need for this class unnecessary. I realize that's a Xerces issue and not a Saxon issue, but maybe somebody here knows the answer? Cheers, Eliot

    (1-2/2)

    Please register to reply