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
Jun 8, 2009

Use a Validator to Validate a DOMSource

This code snippet creates a Validator that you can use to validate an XML document represented as a DOMSource.

//create a DocumentBuilderFactory object
DBF=DocumentBuilderFactory.newInstance();
      
//activating namespaces support
DBF.setNamespaceAware(true);
       
//create a DocumentBuilder object
DB=DBF.newDocumentBuilder();
       
//get the Document from XML document
D=DB.parse(new File(XMLdoc)); 

//create a SchemaFactory object
SchemaFactory SF=SchemaFactory.newInstance
(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
                     
//create a Schema object
Schema S=SF.newSchema(new File("schema_name.xsd"));                     
                     
//create a Validator object
Validator V=S.newValidator();

//call validate method
V.validate(new DOMSource(D));
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap