[XOM-interest] Validating a Document against a schema

Michael Kay mike at saxonica.com
Wed May 21 09:34:21 EDT 2008


> You could stream the document through the validator, but if 
> you're creating it with XOM and then validating it, I can't 
> think of a better way. Off the top of my head I'm not aware 
> of any schema validators that work directly on the XOM model.

Saxon will do so. Using the s9api interface:

Processor p = new Processor(true);
XdmNode doc = p.newDocumentBuilder().wrap(xomDocument);
SchemaManager sm = p.getSchemaManager();
sm.load(...the schema...);
sm.newSchemaValidator().validate(doc.asSource());

or you can rely on xsi:schemaLocation to identify the schema if you prefer.

Michael Kay
http://www.saxonica.com/



More information about the XOM-interest mailing list