Create XML validator from XML schema : XML Schema « XML « Java Tutorial






import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

public class Main {
  public static void main(String[] argv) throws Exception {
    String schemaLang = "http://www.w3.org/2001/XMLSchema";
    SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
    Schema schema = factory.newSchema(new StreamSource("sample.xsd"));
    Validator validator = schema.newValidator();
    validator.validate(new StreamSource("sample.xml"));
  }
}








33.19.XML Schema
33.19.1.Create XML validator from XML schema
33.19.2.JAXP 1.3 Datatype API