Package javax.xml.validation
See: Description
-
Class Summary Class Description Schema Immutable in-memory representation of grammar.SchemaFactory Factory that createsSchema
objects. Entry-point to the validation API.SchemaFactoryLoader Factory that createsSchemaFactory
.TypeInfoProvider This class provides access to the type information determined byValidatorHandler
.Validator A processor that checks an XML document againstSchema
.ValidatorHandler Streaming validator that works on SAX stream.
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:
- Document Type Definition (DTD) - XML's built-in schema language.
- W3C XML Schema (WXS) - an object-oriented XML schema language. WXS also provides a type system for constraining the character data of an XML document. WXS is maintained by the World Wide Web Consortium (W3C) and is a W3C Recommendation (that is, a ratified W3C standard specification).
- RELAX NG (RNG) - a pattern-based, user-friendly XML schema language. RNG schemas may also use types to constrain XML character data. RNG is maintained by the Organization for the Advancement of Structured Information Standards (OASIS) and is both an OASIS and an ISO (International Organization for Standardization) standard.
- Schematron - a rules-based XML schema language. Whereas DTD, WXS, and RNG are designed to express the structure of a content model, Schematron is designed to enforce individual rules that are difficult or impossible to express with other schema languages. Schematron is intended to supplement a schema written in structural schema language such as the aforementioned. Schematron is in the process of becoming an ISO standard.
Previous versions of JAXP supported validation as a feature of an XML parser, represented by
either a SAXParser
or DocumentBuilder
instance.
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:
- Support for additional schema langauges. As of JDK 1.5, the two most popular JAXP parser implementations, Crimson and Xerces, only support a subset of the available XML schema languages. The Validation API provides a standard mechanism through which applications may take of advantage of specialization validation libraries which support additional schema languages.
- Easy runtime coupling of an XML instance and schema. Specifying the location of a schema to use for validation with JAXP parsers can be confusing. The Validation API makes this process simple (see example below).
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 Schema
with the validation API
and associate it with a DocumentBuilderFactory
or a SAXParserFactory
instance
by using the DocumentBuilderFactory.setSchema(Schema)
and SAXParserFactory.setSchema(Schema)
methods. You should not both set a schema and call setValidating(true)
on a parser factory. The former technique
will cause parsers to use the new validation API; the latter will cause parsers to use their own internal validation
facilities. Turning on both of these options simultaneously will cause either redundant behavior or error conditions.
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 04:32:41 Cette version de la page est en cache (à la date du 22/12/2024 04:32:41) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 20/10/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/xml/validation/package-summary.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.