Validates the specified input and send the augmented validation
result to the specified output.
This method places the following restrictions on the types of
the Source
/Result
accepted.
Source / Result Accepted |
|
StreamSource |
SAXSource |
DOMSource |
StAXSource |
null |
OK |
OK |
OK |
OK |
StreamResult |
OK |
IllegalArgumentException |
IllegalArgumentException |
IllegalArgumentException |
SAXResult |
IllegalArgumentException |
OK |
IllegalArgumentException |
IllegalArgumentException |
DOMResult |
IllegalArgumentException |
IllegalArgumentException |
OK |
IllegalArgumentException |
StAXResult |
IllegalArgumentException |
IllegalArgumentException |
IllegalArgumentException |
OK |
To validate one Source
into another kind of
Result
, use the identity transformer (see
TransformerFactory.newTransformer()
).
Errors found during the validation is sent to the specified
ErrorHandler
.
If a document is valid, or if a document contains some errors
but none of them were fatal and the ErrorHandler
didn't
throw any exception, then the method returns normally.
Parameters:
-
source - XML to be validated. Must be an XML document or
XML element and must not be null. For backwards compatibility,
the results of attempting to validate anything other than
a document or element are implementation-dependent.
Implementations must either recognize and process the input
or throw an IllegalArgumentException.
-
result - The
Result
object that receives (possibly augmented)
XML. This parameter can be null if the caller is not interested
in it.
Note that when a
DOMResult
is used,
a validator might just pass the same DOM node from
DOMSource
to
DOMResult
(in which case
source.getNode()==result.getNode()
),
it might copy the entire DOM tree, or it might alter the
node given by the source.
Throws:
-
IllegalArgumentException - If the
Result
type doesn't match the
Source
type of if the
Source
is an XML artifact that the implementation cannot
validate (for example, a processing instruction).
-
SAXException - If the
ErrorHandler
throws a
SAXException
or
if a fatal error is found and the
ErrorHandler
returns
normally.
-
IOException - If the validator is processing a
SAXSource
and the
underlying {@link org.xml.sax.XMLReader} throws an
IOException
.
-
NullPointerException - If the
source
parameter is
null
.
See Also:
Validator.validate(Source source)
,