JAXP Schema Validation in Java5 and Java6

I have had a little battle with schema validation of XML documents and thought I would share it with the world.
I wrote the below code on Java5, thinking this was a way of validating a piece of XML against a schema definition. And indeed, it does work on Java5:

SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setSchema(sf.newSchema(schemaUrl));
DocumentBuilder [...]

June 25, 2009  Tags: , , ,   Posted in: Programming  One Comment