Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Jul 25, 2006

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/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");
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap