Package org.custommonkey.xmlunit.jaxp13
Class Validator
- java.lang.Object
-
- org.custommonkey.xmlunit.jaxp13.Validator
-
public class Validator extends java.lang.Object
Validator class based ofjavax.xml.validation
.This class provides support for validating schema definitions as well as instance documents. It defaults to the W3C XML Schema 1.0 but can be used to validate against any schema language supported by your SchemaFactory implementation.
An implementation detail of
javax.xml.validation.Validator
leaks into this class: anyxsi:schemaLocation
orxsi:noSchemaLocation
attribute of the instance document will be ignored if any schema source has been set. This means you must either specify all sources or none of them to successfully validate instances.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<javax.xml.transform.Source>
sources
private JAXPValidator
validator
-
Constructor Summary
Constructors Modifier Constructor Description Validator()
validates using W3C XML Schema 1.0.Validator(java.lang.String schemaLanguage)
validates using the specified schema language.protected
Validator(java.lang.String schemaLanguage, javax.xml.validation.SchemaFactory factory)
validates using the specified schema language or factory.Validator(javax.xml.validation.SchemaFactory factory)
validates using the specified schema factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSchemaSource(javax.xml.transform.Source s)
Adds a source for the schema defintion.java.util.List<org.xml.sax.SAXParseException>
getInstanceErrors(javax.xml.transform.Source instance)
Obtain a list of all errors in the given instance.java.util.List<org.xml.sax.SAXParseException>
getSchemaErrors()
Obtain a list of all errors in the schema defintion.boolean
isInstanceValid(javax.xml.transform.Source instance)
Is the given schema instance valid according to the configured schema definition(s)?boolean
isSchemaValid()
Is the given schema definition valid?private static java.util.List<org.xml.sax.SAXParseException>
problemToExceptionList(java.lang.Iterable<ValidationProblem> problems)
-
-
-
Field Detail
-
sources
private final java.util.ArrayList<javax.xml.transform.Source> sources
-
validator
private final JAXPValidator validator
-
-
Constructor Detail
-
Validator
public Validator()
validates using W3C XML Schema 1.0.
-
Validator
public Validator(java.lang.String schemaLanguage)
validates using the specified schema language.- Parameters:
schemaLanguage
- the schema language to use - seeSchemaFactory
.
-
Validator
public Validator(javax.xml.validation.SchemaFactory factory)
validates using the specified schema factory.
-
Validator
protected Validator(java.lang.String schemaLanguage, javax.xml.validation.SchemaFactory factory)
validates using the specified schema language or factory.- Parameters:
schemaLanguage
- the schema language to use - seeSchemaFactory
.factory
- the concrete factory to use. If this is non-null, the first argument will be ignored.
-
-
Method Detail
-
addSchemaSource
public void addSchemaSource(javax.xml.transform.Source s)
Adds a source for the schema defintion.
-
isSchemaValid
public boolean isSchemaValid()
Is the given schema definition valid?
-
getSchemaErrors
public java.util.List<org.xml.sax.SAXParseException> getSchemaErrors()
Obtain a list of all errors in the schema defintion.The list contains
SAXParseException
s.
-
isInstanceValid
public boolean isInstanceValid(javax.xml.transform.Source instance)
Is the given schema instance valid according to the configured schema definition(s)?- Throws:
XMLUnitRuntimeException
- if the schema definition is invalid or the Source is a SAXSource and the underlying XMLReader throws an IOException (seevalidate in Validator
).
-
getInstanceErrors
public java.util.List<org.xml.sax.SAXParseException> getInstanceErrors(javax.xml.transform.Source instance)
Obtain a list of all errors in the given instance.The list contains
SAXParseException
s.- Throws:
XMLUnitRuntimeException
- if the schema definition is invalid or the Source is a SAXSource and the underlying XMLReader throws an IOException (seevalidate in Validator
).
-
problemToExceptionList
private static java.util.List<org.xml.sax.SAXParseException> problemToExceptionList(java.lang.Iterable<ValidationProblem> problems)
-
-