devxlogo

Using XMLSchema DOM and SAX in JAXP 1.2

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");
See also  11 Effective Keyword Research Tools and Techniques
devxblackblue

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.

About Our Journalist