Class XmlSchemaValidator

java.lang.Object
nl.knaw.dans.lib.util.XmlSchemaValidator

public class XmlSchemaValidator extends Object
Container that keeps a number of configured XML Schema validators. Each validator has an alias. While it is possible to use the full namespace URI as alias, this is not required. For example, the alias could be a simple name such as "ddm" or "emd".
  • Field Details

  • Constructor Details

    • XmlSchemaValidator

      public XmlSchemaValidator(@NonNull @NonNull Map<String,URI> aliasToSchemaLocation, boolean failOnWarning)
      Constructs an XmlSchemaValidator that can validate XML documents against multiple XML Schemas.
      Parameters:
      aliasToSchemaLocation - a map of schema aliases to schema locations (the URL of the XSD, not the namespace)
    • XmlSchemaValidator

      public XmlSchemaValidator(Map<String,URI> aliasToSchemaLocation)
      Constructs an XmlSchemaValidator that can validate XML documents against multiple XML Schemas.
      Parameters:
      aliasToSchemaLocation - a map of schema aliases to schema locations (the URL of the XSD, not the namespace)
  • Method Details

    • validateDocument

      public List<SAXParseException> validateDocument(Node node, String schemaAlias) throws IOException, SAXException
      Validates the document loaded into node against the schema mapped to schemaAlias. Note that a more complete validation can be performed by using a Source instead of a Node, as fatal errors will already be raised when parsing the text into a DOM tree.
      Parameters:
      node - the XML document to validate
      schemaAlias - the alias of the schema to validate against
      Returns:
      a list of SAXParseExceptions encountered during validation; an empty list indicates the document is valid
      Throws:
      IOException - if the schema cannot be read
      SAXException - if validation could not be performed
    • validateDocument

      public List<SAXParseException> validateDocument(Source source, String schemaAlias) throws IOException, SAXException
      Validates the document loaded into node against the schema mapped to schemaAlias.
      Parameters:
      source - the XML document to validate
      schemaAlias - the alias of the schema to validate against
      Returns:
      a list of SAXParseExceptions encountered during validation; an empty list indicates the document is valid
      Throws:
      IOException - if the schema cannot be read
      SAXException - if validation could not be performed