org.custommonkey.xmlunit

Class Validator

public class Validator extends DefaultHandler implements ErrorHandler

Validates XML against its internal or external DOCTYPE, or a completely different DOCTYPE. Usage:
Examples and more at xmlunit.sourceforge.net
Constructor Summary
protected Validator(InputSource inputSource, boolean usingDoctypeReader)
Baseline constructor: called by all others
Validator(Document document, String systemID, String doctype)
DOM-style constructor: allows Document validation post-manipulation of the DOM tree's contents.
Validator(Reader readerForValidation)
Basic constructor.
Validator(Reader readerForValidation, String systemID)
Extended constructor.
Validator(Reader readerForValidation, String systemID, String doctype)
Full constructor.
Method Summary
voidassertIsValid()
Assert that a document is valid.
voiderror(SAXParseException exception)
ErrorHandler interface method
voidfatalError(SAXParseException exception)
ErrorHandler interface method
booleanisValid()
Perform the validation of the source against DTD
InputSourceresolveEntity(String publicId, String systemId)
Entity Resolver method: allows us to override an existing systemID referenced in the markup DOCTYPE instruction
StringtoString()
voiduseXMLSchema(boolean use)
Turn on XML Schema validation.
voidwarning(SAXParseException exception)
ErrorHandler interface method

Constructor Detail

Validator

protected Validator(InputSource inputSource, boolean usingDoctypeReader)
Baseline constructor: called by all others

Parameters: inputSource usingDoctypeReader

Throws: ParserConfigurationException SAXException

Validator

public Validator(Document document, String systemID, String doctype)
DOM-style constructor: allows Document validation post-manipulation of the DOM tree's contents. This takes a fairly tortuous route to validation as DOM level 2 does not allow creation of Doctype nodes. The supplied systemId and doctype name will replace any Doctype settings in the Document.

Parameters: document systemID doctype

Throws: ParserConfigurationException if unable to turn validation feature on in JAXP factory SAXException if unable to obtain new Sax parser via JAXP factory

Validator

public Validator(Reader readerForValidation)
Basic constructor. Validates the contents of the Reader using the DTD or schema referenced by those contents.

Parameters: readerForValidation

Throws: ParserConfigurationException if unable to turn validation feature on in JAXP factory SAXException if unable to obtain new Sax parser via JAXP factory

Validator

public Validator(Reader readerForValidation, String systemID)
Extended constructor. Validates the contents of the Reader using the DTD specified with the systemID. There must be DOCTYPE instruction in the markup that references the DTD or else the markup will be considered invalid: if there is no DOCTYPE in the markup use the 3-argument constructor

Parameters: readerForValidation systemID

Throws: ParserConfigurationException if unable to turn validation feature on in JAXP factory SAXException if unable to obtain new Sax parser via JAXP factory

Validator

public Validator(Reader readerForValidation, String systemID, String doctype)
Full constructor. Validates the contents of the Reader using the DTD specified with the systemID and named with the doctype name.

Parameters: readerForValidation systemID doctype

Throws: ParserConfigurationException SAXException

Method Detail

assertIsValid

public void assertIsValid()
Assert that a document is valid.

error

public void error(SAXParseException exception)
ErrorHandler interface method

Parameters: exception

Throws: SAXException

fatalError

public void fatalError(SAXParseException exception)
ErrorHandler interface method

Parameters: exception

Throws: SAXException

isValid

public boolean isValid()
Perform the validation of the source against DTD

Returns: true if the input supplied to the constructor passes validation, false otherwise

resolveEntity

public InputSource resolveEntity(String publicId, String systemId)
Entity Resolver method: allows us to override an existing systemID referenced in the markup DOCTYPE instruction

Parameters: publicId systemId

Returns: the sax InputSource that points to the overridden systemID

toString

public String toString()

Returns: class name appended with validation messages

useXMLSchema

public void useXMLSchema(boolean use)
Turn on XML Schema validation. Calling this method sets the featues http://apache.org/xml/features/validation/schema & http://apache.org/xml/features/validation/dynamic to true. Currently this feature only works with the Xerces 2 XML parser

Parameters: use indicate that XML Schema should be used to validate documents.

Throws: SAXException

warning

public void warning(SAXParseException exception)
ErrorHandler interface method

Parameters: exception

Throws: SAXException