|
Préférences
Moteurs de recherche
|
|||||||||||||
| JavaTM 2 Platform Std. Ed. v1.6.0
Package javax.xml.validationThis package provides an API for validation of XML documents.
See:
Package javax.xml.validation Description
This package provides an API for validation of XML documents. Validation is the process of verifying that an XML document is an instance of a specified XML schema. An XML schema defines the content model (also called a grammar or vocabulary) that its instance documents will represent. There are a number of popular technologies available for creating an XML schema. Some of the most popular include:
Previous versions of JAXP supported validation as a feature of an XML parser, represented by
either a The JAXP validation API decouples the validation of an instance document from the parsing of an XML document. This is advantageous for several reasons, some of which are:
Usage example. The following example demonstrates validating an XML document with the Validation API (for readability, some exception handling is not shown):
// parse an XML document into a DOM tree
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File("instance.xml"));
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File("mySchema.xsd"));
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an instance document
Validator validator = schema.newValidator();
// validate the DOM tree
try {
validator.validate(new DOMSource(document));
} catch (SAXException e) {
// instance document is invalid!
}
The JAXP parsing API has been integrated with the Validation API. Applications may create a
Copyright 2003 Sun Microsystems, Inc. All rights reserved
|
||||||||||||||