286N/A<?xml version="1.0" encoding="UTF-8"?>
286N/A<!--
286N/ACopyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
286N/ADO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A
286N/AThis code is free software; you can redistribute it and/or modify it
286N/Aunder the terms of the GNU General Public License version 2 only, as
286N/Apublished by the Free Software Foundation. Oracle designates this
286N/Aparticular file as subject to the "Classpath" exception as provided
286N/Aby Oracle in the LICENSE file that accompanied this code.
286N/A
286N/AThis code is distributed in the hope that it will be useful, but WITHOUT
286N/AANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286N/AFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286N/Aversion 2 for more details (a copy is included in the LICENSE file that
286N/Aaccompanied this code).
286N/A
286N/AYou should have received a copy of the GNU General Public License version
286N/A2 along with this work; if not, write to the Free Software Foundation,
286N/AInc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286N/A
286N/APlease contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
286N/Aor visit www.oracle.com if you need additional information or have any
286N/Aquestions.
286N/A-->
286N/A
286N/A<!DOCTYPE html
286N/A PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
286N/A "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
286N/A
286N/A<html xmlns="http://www.w3.org/1999/xhtml">
286N/A
286N/A<head>
286N/A <title>javax.xml.validation</title>
286N/A
286N/A <meta name="CVS"
286N/A content="$Id: package.html,v 1.2 2005/06/10 03:50:43 jeffsuttor Exp $" />
286N/A <meta name="AUTHOR"
286N/A content="Jeff.Suttor@Sun.com" />
286N/A</head>
286N/A <body>
286N/A <p>
286N/A This package provides an API for validation of XML documents. <em>Validation</em> is the process of verifying
286N/A that an XML document is an instance of a specified XML <em>schema</em>. An XML schema defines the
286N/A content model (also called a <em>grammar</em> or <em>vocabulary</em>) that its instance documents
286N/A will represent.
286N/A </p>
286N/A <p>
286N/A There are a number of popular technologies available for creating an XML schema. Some of the most
286N/A popular include:
286N/A </p>
286N/A <ul>
286N/A <li><strong>Document Type Definition (DTD)</strong> - XML's built-in schema language.</li>
286N/A <li><strong><a href="http://www.w3.org/XML/Schema">W3C XML Schema (WXS)</a></strong> - an object-oriented XML schema
286N/A language. WXS also provides a type system for constraining the character data of an XML document.
286N/A WXS is maintained by the <a href="http://www.w3.org">World Wide Web Consortium (W3C)</a> and is a W3C
286N/A Recommendation (that is, a ratified W3C standard specification).</li>
286N/A <li><strong><a href="http://www.relaxng.org">RELAX NG (RNG)</a></strong> - a pattern-based,
286N/A user-friendly XML schema language. RNG schemas may also use types to constrain XML character data.
286N/A RNG is maintained by the <a href="http://www.oasis-open.org">Organization for the Advancement of
286N/A Structured Information Standards (OASIS)</a> and is both an OASIS and an
286N/A <a href="http://www.iso.org">ISO (International Organization for Standardization)</a> standard.</li>
286N/A <li><strong><a href="http://www.schematron.com/">Schematron</a></strong> - a rules-based XML schema
286N/A language. Whereas DTD, WXS, and RNG are designed to express the structure of a content model,
286N/A Schematron is designed to enforce individual rules that are difficult or impossible to express
286N/A with other schema languages. Schematron is intended to supplement a schema written in
286N/A structural schema language such as the aforementioned. Schematron is in the process
286N/A of becoming an ISO standard.</li>
286N/A </ul>
286N/A <p>
286N/A Previous versions of JAXP supported validation as a feature of an XML parser, represented by
286N/A either a {@link javax.xml.parsers.SAXParser} or {@link javax.xml.parsers.DocumentBuilder} instance.
286N/A </p>
286N/A <p>
286N/A The JAXP validation API decouples the validation of an instance document from the parsing of an
286N/A XML document. This is advantageous for several reasons, some of which are:
286N/A </p>
286N/A <ul>
286N/A <li><strong>Support for additional schema langauges.</strong> As of JDK 1.5, the two most
286N/A popular JAXP parser implementations, Crimson and Xerces, only support a subset of the available
286N/A XML schema languages. The Validation API provides a standard mechanism through which applications
286N/A may take of advantage of specialization validation libraries which support additional schema
286N/A languages.</li>
286N/A <li><strong>Easy runtime coupling of an XML instance and schema.</strong> Specifying the location
286N/A of a schema to use for validation with JAXP parsers can be confusing. The Validation API makes this
286N/A process simple (see <a href="#example-1">example</a> below).</li>
286N/A </ul>
286N/A <p>
286N/A <a name="example-1"><strong>Usage example</strong>.</a> The following example demonstrates validating
286N/A an XML document with the Validation API (for readability, some exception handling is not shown):
286N/A </p>
286N/A <pre>
286N/A
286N/A // parse an XML document into a DOM tree
286N/A DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
286N/A Document document = parser.parse(new File("instance.xml"));
286N/A
286N/A // create a SchemaFactory capable of understanding WXS schemas
286N/A SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
286N/A
286N/A // load a WXS schema, represented by a Schema instance
286N/A Source schemaFile = new StreamSource(new File("mySchema.xsd"));
286N/A Schema schema = factory.newSchema(schemaFile);
286N/A
286N/A // create a Validator instance, which can be used to validate an instance document
286N/A Validator validator = schema.newValidator();
286N/A
286N/A // validate the DOM tree
286N/A try {
286N/A validator.validate(new DOMSource(document));
286N/A } catch (SAXException e) {
286N/A // instance document is invalid!
286N/A }
286N/A</pre>
286N/A <p>
286N/A The JAXP parsing API has been integrated with the Validation API. Applications may create a {@link javax.xml.validation.Schema} with the validation API
286N/A and associate it with a {@link javax.xml.parsers.DocumentBuilderFactory} or a {@link javax.xml.parsers.SAXParserFactory} instance
286N/A by using the {@link javax.xml.parsers.DocumentBuilderFactory#setSchema(Schema)} and {@link javax.xml.parsers.SAXParserFactory#setSchema(Schema)}
286N/A methods. <strong>You should not</strong> both set a schema and call <code>setValidating(true)</code> on a parser factory. The former technique
286N/A will cause parsers to use the new validation API; the latter will cause parsers to use their own internal validation
286N/A facilities. <strong>Turning on both of these options simultaneously will cause either redundant behavior or error conditions.</strong>
286N/A </p>
286N/A </body>
286N/A</html>