JUnit test for RELAX NG Schemas

public void testRELAXNGValid() {

  // some of this might be moved into fixtures
  DocumentBuilder parser 
    = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  Document document = parser.parse(new File("filename.xml"));

  SchemaFactory factory 
    = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
  Source source = new StreamSource(new File("plist.rnc"));
  Schema schema = factory.newSchema(source);
  Validator validator = schema.newValidator();
 
  validator.validate(new DOMSource(document));
  // throws exception if document is invalid

}

Previous | Next | Top | Cafe con Leche

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