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

Create XML validator from XML schema

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 = "";
    SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
    Schema schema = factory.newSchema(new StreamSource("sample.xsd"));
    Validator validator = schema.newValidator();
    validator.validate(new StreamSource("sample.xml"));


Related examples in the same category

1.Validate xml against XML Schema
2.Validate xml against the schema
3.Encoder and Decoder for XML element and attribute names
4.XML constants
5.Resolve relative URIs and SystemID strings into absolute URIs
6.Provides a trace of the schema type information for elements and attributes in an XML document.
7.Use JAXP Validation API to create a validator and validate input from a DOM which contains inline schemas and multiple validation roots.
8.Return the first element child with the specified qualified name.
9.XSDWriter is a helper class to produce xml schemas in Java.