Package org.custommonkey.xmlunit.jaxp13
Class Validator
java.lang.Object
org.custommonkey.xmlunit.jaxp13.Validator
Validator class based of
javax.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: any
xsi:schemaLocation
or xsi: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.
-
Constructor Summary
ModifierConstructorDescriptionvalidates using W3C XML Schema 1.0.validates using the specified schema language.protected
Validator
(String schemaLanguage, SchemaFactory factory) validates using the specified schema language or factory.Validator
(SchemaFactory factory) validates using the specified schema factory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a source for the schema defintion.getInstanceErrors
(Source instance) Obtain a list of all errors in the given instance.Obtain a list of all errors in the schema defintion.boolean
isInstanceValid
(Source instance) Is the given schema instance valid according to the configured schema definition(s)?boolean
Is the given schema definition valid?
-
Constructor Details
-
Validator
public Validator()validates using W3C XML Schema 1.0. -
Validator
validates using the specified schema language.- Parameters:
schemaLanguage
- the schema language to use - seeSchemaFactory
.
-
Validator
validates using the specified schema factory.- Parameters:
factory
- the concrete factory to use. If this is non-null, the first argument will be ignored.
-
Validator
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 Details
-
addSchemaSource
Adds a source for the schema defintion.- Parameters:
s
- the source to add
-
isSchemaValid
public boolean isSchemaValid()Is the given schema definition valid?- Returns:
- whether the given schema definition is valid
-
getSchemaErrors
Obtain a list of all errors in the schema defintion.The list contains
SAXParseException
s.- Returns:
- a list of all errors in the schema definition
-
isInstanceValid
Is the given schema instance valid according to the configured schema definition(s)?- Parameters:
instance
- the instance to check- Returns:
- whether the instance is valid
- 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
Obtain a list of all errors in the given instance.The list contains
SAXParseException
s.- Parameters:
instance
- the instance to check- Returns:
- a list of all errors in the given instance
- Throws:
XMLUnitRuntimeException
- if the schema definition is invalid or the Source is a SAXSource and the underlying XMLReader throws an IOException (seevalidate in Validator
).
-