Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import javax.xml.validation.*; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamSource; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { public static String xsdUrl = "src/com/esbqualificationtool/xmlHelper/ScenarioSchema.xsd"; public static boolean doesXMLMatchXSD(String xmlUrl) throws SAXException, FileNotFoundException, IOException { boolean doesMatchXSD = false; SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); SAXSource sourceXSD = new SAXSource(new InputSource(new FileInputStream(new File(xsdUrl)))); Schema schema = factory.newSchema(sourceXSD); Validator validator = (Validator) schema.newValidator(); validator.validate(new StreamSource(new File(xmlUrl))); doesMatchXSD = true; return doesMatchXSD; } }