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...");
See also  5 Ways to Improve Customer Experience
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