Sunday 31 July 2011

Validate xml against the schema

    

import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class SchemaParserXerces implements ErrorHandler {

  public void warning(SAXParseException ethrows SAXException {
    throw e;
  }

  public void error(SAXParseException ethrows SAXException {
    throw e;
  }

  public void fatalError(SAXParseException ethrows SAXException {
    throw e;
  }

  public static void main(String[] argsthrows Exception {
    DOMParser d = new DOMParser();
    d.setFeature("http://xml.org/sax/features/validation"true);
    d.setFeature("http://apache.org/xml/features/validation/schema"true);
    d.setFeature("http://apache.org/xml/features/validation/schema-full-checking"true);
    d.setErrorHandler(new SchemaParserXerces());
    d.parse(args[0]);
    System.out.println("Parsed successfully");
  }

}

   
    
    
  

No comments:

Post a Comment