// get DOM Implementation using DOM Registry
System.setProperty(DOMImplementationRegistry.PROPERTY,"org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS)registry.getDOMImplementation("LS");
// create DOMBuilder
builder = impl.createDOMParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = builder.getConfig();
// create Error Handler
DOMErrorHandler errorHandler = new DOM3();
// create filter
DOMParserFilter 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.getConfig();
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
DOMSerializer domWriter = impl.createDOMSerializer();
System.out.println("Serializing document... ");
config = domWriter.getConfig();
config.setParameter("xml-declaration", Boolean.FALSE);
//config.setParameter("validate",errorHandler);