1 21 22 package nu.xom.samples; 23 24 import java.io.IOException ; 25 26 import nu.xom.Builder; 27 import nu.xom.ParsingException; 28 29 import org.xml.sax.SAXException ; 30 import org.xml.sax.XMLReader ; 31 import org.xml.sax.helpers.XMLReaderFactory ; 32 33 43 public class SchemaValidator { 44 45 public static void main(String [] args) { 46 47 if (args.length <= 0) { 48 System.out.println( 49 "Usage: java nu.xom.samples.SchemaValidator URL"); 50 return; 51 } 52 53 try { 54 XMLReader xerces = XMLReaderFactory.createXMLReader( 55 "org.apache.xerces.parsers.SAXParser"); 56 xerces.setFeature( 57 "http://apache.org/xml/features/validation/schema", 58 true 59 ); 60 61 Builder parser = new Builder(xerces, true); 62 parser.build(args[0]); 63 System.out.println(args[0] + " is schema valid."); 64 } 65 catch (SAXException ex) { 66 System.out.println("Could not load Xerces."); 67 System.out.println(ex.getMessage()); 68 } 69 catch (ParsingException ex) { 70 System.out.println(args[0] + " is not schema valid."); 71 System.out.println(ex.getMessage()); 72 ex.printStackTrace(); 73 System.out.println(" at line " + ex.getLineNumber() 74 + ", column " + ex.getColumnNumber()); 75 } 76 catch (IOException ex) { 77 System.out.println( 78 "Due to an IOException, Xerces could not check " 79 + args[0] 80 ); 81 ex.printStackTrace(); 82 } 83 84 } 85 86 } | Popular Tags |