Login | Register   
LinkedIn
Google+
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: Advanced
Mar 24, 2008

Validating an XML Document

The following code shows you how to use the DOMImplementationLS and DOMConfiguration classes to validate an XML document only when an XML Schema is present:

DOMImplementationLS DOMiLS=null;

//get a LSParser
LSParser LSP=DOMiLS.createLSParser(
DOMImplementationLS.MODE_SYNCHRONOUS,                                      
"http://www.w3.org/2001/XMLSchema");
       
//get a DOMConfiguration
DOMConfiguration DOMc=LSP.getDomConfig();

//validating
if(DOMc.canSetParameter("schema-type","http://www.w3.org/2001/XMLSchema"))
DOMc.setParameter("schema-type","http://www.w3.org/2001/XMLSchema");
else System.out.println("Error...");

//use validate-if-schema
if(DOMc.canSetParameter("validate-if-schema",true))
   DOMc.setParameter("validate-if-schema",true);
   else System.out.println("Error...");
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap