devxlogo

Validating an XML Document

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 LSParserLSParser LSP=DOMiLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,                                      "http://www.w3.org/2001/XMLSchema");       //get a DOMConfigurationDOMConfiguration DOMc=LSP.getDomConfig();//validatingif(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-schemaif(DOMc.canSetParameter("validate-if-schema",true))   DOMc.setParameter("validate-if-schema",true);   else System.out.println("Error...");

devx-admin

Share the Post: