if (argv.length == 0) {
printUsage();
System.exit(1);
}
try {
// get DOM Implementation using DOM Registry
System.setProperty(DOMImplementationRegistry.PROPERTY,"org.apache.xerces.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS)registry.getDOMImplementation("LS");
// create DOMBuilder
builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = builder.getDomConfig();
// create Error Handler
DOMErrorHandler errorHandler = new DOM3();
// create filter
LSParserFilter filter = new DOM3();
builder.setFilter(filter);
// set error handler
config.setParameter("error-handler", errorHandler);
// set validation feature
//config.setParameter("validate", Boolean.FALSE);
config.setParameter("validate",Boolean.TRUE);
// set schema language
config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
//config.setParameter("psvi",Boolean.TRUE);
//config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
// set schema location
config.setParameter("schema-location","personal.xsd");
// parse document
System.out.println("Parsing "+argv[0]+"...");
Document doc = builder.parseURI(argv[0]);
// set error handler on the Document
config = doc.getDomConfig();
config.setParameter("error-handler", errorHandler);
// set validation feature
config.setParameter("validate", Boolean.TRUE);
config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
//config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
config.setParameter("schema-location","data/personal.xsd");
// remove comments from the document
config.setParameter("comments", Boolean.FALSE);
System.out.println("Normalizing document... ");
doc.normalizeDocument();
// create DOMWriter
LSSerializer domWriter = impl.createLSSerializer();
System.out.println("Serializing document... ");
config = domWriter.getDomConfig();
config.setParameter("xml-declaration", Boolean.FALSE);
//config.setParameter("validate",errorHandler);
// serialize document to standard output
//domWriter.writeNode(System.out, doc);
LSOutput dOut = impl.createLSOutput();
dOut.setByteStream(System.out);
domWriter.write(doc,dOut);
} catch ( Exception ex ) {
ex.printStackTrace();
}