importjavax.xml.XMLConstants;importjavax.xml.transform.Source;importjavax.xml.transform.stream.StreamSource;importjavax.xml.validation.*;...URLschemaFile=newURL("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd");SourcexmlFile=newStreamSource(newFile("web.xml"));SchemaFactoryschemaFactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);Schemaschema=schemaFactory.newSchema(schemaFile);Validatorvalidator=schema.newValidator();try{validator.validate(xmlFile);System.out.println(xmlFile.getSystemId()+" is valid");}catch(SAXExceptione){System.out.println(xmlFile.getSystemId()+" is NOT valid");System.out.println("Reason: "+e.getLocalizedMessage());}