To take advantage of the power of XMLSchema in a SAX or DOM application, you simply have to set two properties. In JAXP 1.3, use the
javax.xml.validation package.
The two properties are:
http://java.sun.com/xml/jaxp/properties/schemaLanguage
http://java.sun.com/xml/jaxp/properties/schemaSource
In a "SAX application":
...
SAXParserFactory SAXpf=SAXParserFactory.newInstance();
...
SAXpf.setNamespaceAware(true);
SAXpf.setValidating(true);
...
SAXParser SAXparser=SAXpf.newSAXParser();
...
try
{
SAXparser.setProperty ("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
}
catch (SAXNotRecognizedException e)
{
System.out.println("ERROR:"+e.getMessage());
}
SAXparser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource",
new File("C://Data_Local//XML//XMLSchema//AutoDealer.xsd"));
- in a "DOM application":
...
DBF=DocumentBuilderFactory.newInstance();
...
DBF.setNamespaceAware(true);
DBF.setValidating(true);
...
try
{
DBF.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
}
catch (SAXNotRecognizedException e)
{
System.out.println("ERROR:"+e.getMessage());
}
DBF.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource",
"C://Data_Local//XML//XMLSchema//AutoDealer.xsd");