public class Validator extends Object
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.
Modifier | Constructor and Description |
---|---|
|
Validator()
validates using W3C XML Schema 1.0.
|
|
Validator(SchemaFactory factory)
validates using the specified schema factory.
|
|
Validator(String schemaLanguage)
validates using the specified schema language.
|
protected |
Validator(String schemaLanguage,
SchemaFactory factory)
validates using the specified schema language or factory.
|
Modifier and Type | Method and Description |
---|---|
void |
addSchemaSource(Source s)
Adds a source for the schema defintion.
|
List<SAXParseException> |
getInstanceErrors(Source instance)
Obtain a list of all errors in the given instance.
|
List<SAXParseException> |
getSchemaErrors()
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 |
isSchemaValid()
Is the given schema definition valid?
|
public Validator()
public Validator(String schemaLanguage)
schemaLanguage
- the schema language to use - see SchemaFactory
.public Validator(SchemaFactory factory)
protected Validator(String schemaLanguage, SchemaFactory factory)
schemaLanguage
- the schema language to use - see SchemaFactory
.factory
- the concrete factory to use. If this is
non-null, the first argument will be ignored.public void addSchemaSource(Source s)
public boolean isSchemaValid()
public List<SAXParseException> getSchemaErrors()
The list contains SAXParseException
s.
public boolean isInstanceValid(Source instance)
XMLUnitRuntimeException
- if the schema definition is
invalid or the Source is a SAXSource and the underlying
XMLReader throws an IOException (see validate in
Validator
).public List<SAXParseException> getInstanceErrors(Source instance)
The list contains SAXParseException
s.
XMLUnitRuntimeException
- if the schema definition is
invalid or the Source is a SAXSource and the underlying
XMLReader throws an IOException (see validate in
Validator
).Copyright © 2001–2017 XMLUnit. All rights reserved.