devxlogo

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...");

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

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.