JAXP: how to check org.w3c.dom.Document against XML Schema

How to check (already parsed) org.w3c.dom.Document for XML Schema using JAXP?

+6
java xml validation xsd jaxp
source share
1 answer

You can use the javax.xml.validation API for this.

 SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); URL schemaURL = // The URL to your XML Schema; Schema schema = sf.newSchema(schemaURL); Validator validator = schema.newValidator(); DOMSource source = new DOMSource(xmlDOM); validator.validate(source); 

The example below demonstrates how to test a JAXB object model for a schema, but you will see that it is easy to replace the JAXBSource DOMSource for the DOM:

+12
source share

All Articles