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 fatalError(
) methods.
Before calling validate( ), a
Validator may also be configured with
setResourceResolver(
),
setFeature( ), and
setProperty( ).
public abstract class
Validator {
// Protected Constructors
protected
Validator ( );
// Public Instance Methods
public abstract org.xml.sax.ErrorHandler
getErrorHandler ( );
public boolean
getFeature (String
name )
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException;
public Object
getProperty (String
name )
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException;
public abstract org.w3c.dom.ls.LSResourceResolver
getResourceResolver ( );
public abstract void
reset ( );
public abstract void
setErrorHandler (org.xml.sax.ErrorHandler
errorHandler );
public void
setFeature (String
name , boolean
value )
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException;
public void
setProperty (String
name , Object
object )
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException;
public abstract void
setResourceResolver (org.w3c.dom.ls.LSResourceResolver
resourceResolver );
public void
validate (javax.xml.transform.Source
source )
throws org.xml.sax.SAXException, java.io.IOException;
public abstract void
validate (javax.xml.transform.Source
source ,
javax.xml.transform.Result
result )
throws org.xml.sax.SAXException, java.io.IOException;
}