With the schemalocation specified in the XML Document using the schemaLocation or noNamespaceSchemaLocation attributes.
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware( true);
factory.setValidating( true);
factory.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( new Inputsource( "test.xml"));
} catch ( ParserConfigurationException e) {
e.printStackTrace();
} catch ( SAXException e) {
e.printStackTrace();
} catch ( IOException e) {
e.printStackTrace();
}
With the schemalocation specified by the 'http://java.sun.com/xml/jaxp/properties/schemaSource' property.
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware( true);
factory.setValidating( true);
factory.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
factory.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource",
"file:test2.xsd");
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( new Inputsource( "test.xml"));
} catch ( ParserConfigurationException e) {
e.printStackTrace();
} catch ( SAXException e) {
e.printStackTrace();
} catch ( IOException e) {
e.printStackTrace();
}