devxlogo

Using XMLSchema DOM and SAX in JAXP 1.2

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/schemaLanguagehttp://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");

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.