How to check (already parsed) org.w3c.dom.Document for XML Schema using JAXP?
org.w3c.dom.Document
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: