RE: Schema-type-aware SAX processing
> I have data that may be arbitrarily large and may conform to arbitrary > XSDL schemata. Because of the size, I want to process the > document as an > event stream (hence SAX), and I want to make different processing > decisions based on the declared types from the schema and based on the > ultimate base types, if there's any type inheritance. > > What's the right tool? Perl is the language of choice, but > I'm flexible. > > I've looked at libxml2 (and XML::LibXML), Xerces-C++ (and > Xerces-p/XML::Xerces), and XSV. They are all focused on > validation; the > document is checked as to whether it fulfills the schema, but > there does > not seem to be a straightforward way to say, "Hi. I'm an > element. What > type am I?" > > What am I missing? Will SAXON-SA provide this ability? > There's an API in JAXP 1.3 (available as part of JDK 1.5) that provides this information; it's implemented both by Xerces and by Saxon-SA. It's somewhat clumsy, however. It's done through the interface ValidatorHandler which extends ContentHandler, and which allows you after a call on startElement to get a TypeInfo object giving information about the type of the element or any of its attributes. There's an example of its use in the SchemaValidatorHandlerExample.java program included in the Saxon-SA distribution. Saxon's own SAX-like interface, the Receiver interface, provides type information natively as part of each startElement or attribute event. This also provides you with access to the schema components in considerably greater detail than the TypeInfo interface: though it's all Saxon-specific. Michael Kay http://www.saxonica.com/
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format