Validating via JUnit

    public void testValidOutput() throws SAXException, IOEXception {
    
      File f = new File("filename.xml");
      InputSource in = new InputSource(new FileInputStream(f));
      
      XMLReader parser = XMLReaderFactory.createXMLReader(); 
      parser.setFeature("http://xml.org/sax/features/validation", true);
      parser.setErrorHandler(new ErrorHandler() {

        public void warning(SAXParseException exception) {
          // skip
        }

        public void error(SAXParseException exception) throws SAXException {
          throw exception;      
        }

        public void fatalError(SAXParseException exception) throws SAXException {
          throw exception;       
        }
          
      });
      parser.parse(in);
    
    } 

Previous | Next | Top | Cafe con Leche

Copyright 2005, 2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 28, 2005