Class XSDValidator

  • All Implemented Interfaces:
    DocumentValidator

    public class XSDValidator
    extends Object
    implements DocumentValidator
    This class implements the DocumentValidor interface for XML Schema (XSD) validation.
    • Constructor Detail

      • XSDValidator

        public XSDValidator​(String filename)
                     throws ValidatorException
        Construct an XSD Validator with the given XML Schema definition (XSD) file.
        Parameters:
        filename - The file containing the XML schema definition
        Throws:
        ValidatorException - if there is an error reasing the schema
      • XSDValidator

        public XSDValidator​(InputStream stream)
                     throws ValidatorException
        Construct an XSD Validator with the XML Schema definition provided in the given input stream. Note that the 'reload' method is disabled when this constructor is used.
        Parameters:
        stream - the InputStream containing the XML schema definition
        Throws:
        ValidatorException - if there is an error reasing the schema
    • Method Detail

      • reload

        public void reload()
                    throws ValidatorException
        Reload the XSD file this validator was initialized with.
        Specified by:
        reload in interface DocumentValidator
        Throws:
        ValidatorException - If there is an error reloading the file, or if this validator was initialized with an input stream.
      • validate

        public ValidationResult validate​(byte[] source)
                                  throws ValidatorException
        Validate the given XML document, and return a new ValidationResult structure containing the validation results.
        Specified by:
        validate in interface DocumentValidator
        Parameters:
        source - Byte-array containing the XML document to validate
        Returns:
        A newly initialized ValidationResult containing the results of the validation
        Throws:
        ValidatorException - Thrown when there is an error performing the validation
      • validate

        public ValidationResult validate​(byte[] source,
                                         ValidationResult result)
                                  throws ValidatorException
        Validate the given XML document, and add the validation results to the given ValidationResult structure
        Specified by:
        validate in interface DocumentValidator
        Parameters:
        source - Byte-array containing the XML document to validate
        result - The structure to add the validation results to
        Returns:
        The modified ValidationResult instance
        Throws:
        ValidatorException - Thrown when there is an error performing the validation