Tags

,

         Validator validator = null;

	public int initValidator (File xsdFile) throws SAXException 
         {
		SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		Source schemaFile = new StreamSource(xsdFile);
		Schema schema = factory.newSchema(schemaFile);
		validator = schema.newValidator();
		return 0;
	}

then call this to validate,
         Document xdoc = some xml doc to be validated;
         DOMSource dsrc = new DOMSource(xdoc);
         validator.validate(dsrc);
Advertisements