1 9 10 package org.dom4j.samples.validate; 11 12 import org.dom4j.samples.AbstractDemo; 13 14 import org.dom4j.Document; 15 import org.dom4j.io.OutputFormat; 16 import org.dom4j.io.SAXReader; 17 import org.dom4j.io.XMLWriter; 18 import org.dom4j.util.XMLErrorHandler; 19 20 26 public class XercesDemo extends AbstractDemo { 27 28 public static void main(String [] args) { 29 run(new XercesDemo(), args); 30 } 31 32 public XercesDemo() { 33 } 34 35 public void run(String [] args) throws Exception { 36 if (args.length < 1) { 37 printUsage("no XML document URL specified"); 38 return; 39 } 40 41 parse(args[0]); 42 } 43 44 protected Document parse(String uri) throws Exception { 45 SAXReader reader = new SAXReader(); 46 47 reader.setValidation(true); 48 49 reader 51 .setProperty( 52 "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", 53 "personal.xsd"); 54 55 XMLErrorHandler errorHandler = new XMLErrorHandler(); 57 reader.setErrorHandler(errorHandler); 58 59 Document document = reader.read(uri); 61 62 XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); 64 writer.write(errorHandler.getErrors()); 65 66 return document; 67 } 68 } 69 70 108 | Popular Tags |