438N/A<?
xml version="1.0" encoding="UTF-8"?>
438N/ACopyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. 438N/ADO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 438N/AThis code is free software; you can redistribute it and/or modify it 438N/Aunder the terms of the GNU General Public License version 2 only, as 438N/Apublished by the Free Software Foundation. Oracle designates this 438N/Aparticular file as subject to the "Classpath" exception as provided 438N/Aby Oracle in the LICENSE file that accompanied this code. 438N/AThis code is distributed in the hope that it will be useful, but WITHOUT 438N/AANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 438N/AFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 438N/Aversion 2 for more details (a copy is included in the LICENSE file that 438N/AYou should have received a copy of the GNU General Public License version 438N/A2 along with this work; if not, write to the Free Software Foundation, 438N/AInc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 438N/APlease contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 438N/A PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" content="Jeff.Suttor@Sun.com" />
This package provides an API for validation of XML documents. <
em>Validation</
em> is the process of verifying
that an XML document is an instance of a specified XML <
em>schema</
em>. An XML schema defines the
content model (also called a <
em>grammar</
em> or <
em>vocabulary</
em>) that its instance documents
There are a number of popular technologies available for creating an XML schema. Some of the most
<
li><
strong>Document Type Definition (DTD)</
strong> - XML's built-in schema language.</
li>
language. WXS also provides a type system for constraining the character data of an XML document.
WXS is maintained by the <
a href="http://www.w3.org">World Wide Web Consortium (W3C)</
a> and is a W3C
Recommendation (that is, a ratified W3C standard specification).</
li>
user-friendly XML schema language. RNG schemas may also use types to constrain XML character data.
Structured Information Standards (OASIS)</
a> and is both an OASIS and an
<
a href="http://www.iso.org">ISO (International Organization for Standardization)</
a> standard.</
li>
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.</
li>
Previous versions of JAXP supported validation as a feature of an XML parser, represented by
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:
<
li><
strong>Support for additional schema langauges.</
strong> 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
<
li><
strong>Easy runtime coupling of an XML instance and schema.</
strong> Specifying the location
of a schema to use for validation with JAXP parsers can be confusing. The Validation API makes this
process simple (see <
a href="#example-1">example</
a> below).</
li>
<
a name="example-1"><
strong>Usage example</
strong>.</
a> 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
// create a SchemaFactory capable of understanding WXS schemas
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File("
mySchema.xsd"));
// create a Validator instance, which can be used to validate an instance document
} catch (SAXException e) {
// instance document is invalid!
The JAXP parsing API has been integrated with the Validation API. Applications may create a {@link
javax.
xml.
validation.
Schema} with the validation API
methods. <
strong>You should not</
strong> both set a schema and call <
code>setValidating(true)</
code> 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. <
strong>Turning on both of these options simultaneously will cause either redundant behavior or error conditions.</
strong>