Example: Schema Validating

try {      
  XMLReader xerces = XMLReaderFactory.createXMLReader(
   "org.apache.xerces.parsers.SAXParser"); 
  xerces.setFeature(
   "http://apache.org/xml/features/validation/schema",
    true);                         
  Builder parser = new Builder(xerces, true);
  parser.build(url);
  System.out.println(url + " is schema valid.");
}
catch (SAXException ex) {
  System.out.println("Could not load Xerces.");
}
catch (ParseException ex) {
  System.out.println(url + " is not schema valid.");
  System.out.println(ex.getMessage());
}
catch (IOException ex) { 
  System.out.println("Due to an IOException, Xerces could not check " 
  + url); 
}

Previous | Next | Top | Cafe con Leche

Copyright 2004, 2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified February 9, 2004