Class ValidationDriver


  • public class ValidationDriver
    extends java.lang.Object
    Provides a simplified API for validating XML documents against schemas. This class is neither reentrant nor safe for access from multiple threads.
    Author:
    James Clark
    • Method Detail

      • loadSchema

        public boolean loadSchema​(org.xml.sax.InputSource in)
                           throws org.xml.sax.SAXException,
                                  java.io.IOException
        Loads a schema. Subsequent calls to validate will validate with respect the loaded schema. This can be called more than once to allow multiple documents to be validated against different schemas.
        Parameters:
        in - the InputSource for the schema
        Returns:
        true if the schema was loaded successfully; false otherwise
        Throws:
        java.io.IOException - if an I/O error occurred
        org.xml.sax.SAXException - if an XMLReader or ErrorHandler threw a SAXException
      • validate

        public boolean validate​(org.xml.sax.InputSource in)
                         throws org.xml.sax.SAXException,
                                java.io.IOException
        Validates a document against the currently loaded schema. This can be called multiple times in order to validate multiple documents.
        Parameters:
        in - the InputSource for the document to be validated
        Returns:
        true if the document is valid; false otherwise
        Throws:
        java.lang.IllegalStateException - if there is no currently loaded schema
        java.io.IOException - if an I/O error occurred
        org.xml.sax.SAXException - if an XMLReader or ErrorHandler threw a SAXException
      • getSchemaProperties

        public PropertyMap getSchemaProperties()
        Get the actual properties of the loaded schema
        Returns:
        a PropertyMap with the schema properties
        Throws:
        java.lang.IllegalStateException - if there is no currently loaded schema
      • fileInputSource

        public static org.xml.sax.InputSource fileInputSource​(java.lang.String filename)
        Returns an InputSource for a filename.
        Parameters:
        filename - a String specifying the filename
        Returns:
        an InputSource for the filename
      • fileInputSource

        public static org.xml.sax.InputSource fileInputSource​(java.io.File file)
        Returns an InputSource for a File.
        Parameters:
        file - the File
        Returns:
        an InputSource for the filename
      • uriOrFileInputSource

        public static org.xml.sax.InputSource uriOrFileInputSource​(java.lang.String uriOrFile)
        Returns an InputSource for a string that represents either a file or an absolute URI. If the string looks like an absolute URI, it will be treated as an absolute URI, otherwise it will be treated as a filename.
        Parameters:
        uriOrFile - a String representing either a file or an absolute URI
        Returns:
        an InputSource for the file or absolute URI