Package nl.knaw.dans.lib.util
Class XmlSchemaValidator
java.lang.Object
nl.knaw.dans.lib.util.XmlSchemaValidator
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXmlSchemaValidator(@NonNull Map<String, URI> aliasToSchemaLocation, boolean failOnWarning) Constructs an XmlSchemaValidator that can validate XML documents against multiple XML Schemas.XmlSchemaValidator(Map<String, URI> aliasToSchemaLocation) Constructs an XmlSchemaValidator that can validate XML documents against multiple XML Schemas. -
Method Summary
Modifier and TypeMethodDescriptionvalidateDocument(Source source, String schemaAlias) Validates the document loaded intonodeagainst the schema mapped toschemaAlias.validateDocument(Node node, String schemaAlias) Validates the document loaded intonodeagainst the schema mapped toschemaAlias.
-
Field Details
-
schemaMap
-
-
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
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 intonodeagainst the schema mapped toschemaAlias. 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 validateschemaAlias- 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 readSAXException- if validation could not be performed
-
validateDocument
public List<SAXParseException> validateDocument(Source source, String schemaAlias) throws IOException, SAXException Validates the document loaded intonodeagainst the schema mapped toschemaAlias.- Parameters:
source- the XML document to validateschemaAlias- 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 readSAXException- if validation could not be performed
-