/** * @author Marcel Turcotte (turcotte@site.uottawa.ca) */ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.ErrorHandler; import java.io.File; import java.io.IOException; public class Validator { static public void main( String args[] ) throws ParserConfigurationException, SAXException, IOException { if ( args.length != 1 ) { System.err.println( "Usage: Java Validator file.xml" ); System.exit( 1 ); } DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setValidating( true ); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); parser.setErrorHandler( new ErrorHandler() { public void error( SAXParseException exception ) { System.out.println( "ERROR :: " + exception ); } public void fatalError( SAXParseException exception ) { System.out.println( "FATAL ERROR :: " + exception ); } public void warning( SAXParseException exception ) { System.out.println( "WARNING :: " + exception ); } }); Document document = parser.parse( new File( args[ 0 ] ) ); } }