Name
Validator
Synopsis
A
Validator object
validates an XML document against the Schema from
which the Validator was created. The
validate( )
method
performs validation. Specify the document to be validated with a
DOMSource
or SAXSource
object (from the javax.xml.transform.dom or
javax.xml.transform.sax packages). The
validate( ) method accepts any
javax.xml.transform.Source object as an argument,
but SAXSource and DOMSource are
the only two supported implementations.
The document validation process can also be used to augment the
source document by adding the default values of unspecified
attributes. If you want to capture this augmented form of the
document, pass a Result object to the two-argument
version of validate( ). If the source is a
SAXSource, the result must be a
SAXResult, and if the source is a
DOMSource, the result must be a
DOMResult object.
If the document is valid, the validate( ) method
returns normally. If the document is not valid, validate(
) throws an org.xml.sax.SAXException.
You can alter this somewhat by passing a custom
org.xml.sax.ErrorHandler to
setErrorHandler( ). Validation exceptions are
first passed to the error handler methods, which may throw the
exception or handle them in some other way, such as printing a
message. If the error handler does not throw an exception, the
validate( ) method attempts to continue
validation. The default error handler ignores exceptions passed to
its warn( ) method but throws exceptions passed to
its error( )
and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access