uTools-Manuals/docs/java/javax/xml/validation/package-summary.html

133 lines
9.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="header">
<h1 class="title" title="Package">Package javax.xml.validation</h1>
<div class="docSummary">
<div class="block">
此软件包提供了一个用于验证XML文档的API。
</div>
</div>
<p>See: <a href="#package.description">描述</a></p>
</div><div class="contentContainer">
<ul class="blockList">
<li class="blockList">
<table border="0" cellpadding="3" cellspacing="0" class="typeSummary" summary="Class Summary table, listing classes, and an explanation">
<caption>
<span>类摘要</span>
<span class="tabEnd"> </span>
</caption>
<tbody>
<tr>
<th class="colFirst" scope="col"></th>
<th class="colLast" scope="col">描述</th>
</tr>
</tbody>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../javax/xml/validation/Schema.html" title="class in javax.xml.validation">Schema</a></td>
<td class="colLast">
<div class="block">
不可变的内存中的语法表示。
</div> </td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../javax/xml/validation/SchemaFactory.html" title="class in javax.xml.validation">SchemaFactory</a></td>
<td class="colLast">
<div class="block">
<span>创建<a href="../../../javax/xml/validation/Schema.html" title="javax.xml.validation中的类"><code>Schema</code></a>对象的工厂。</span>
<span>入口点到验证API。</span>
</div> </td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../javax/xml/validation/SchemaFactoryLoader.html" title="class in javax.xml.validation">SchemaFactoryLoader</a></td>
<td class="colLast">
<div class="block">
<span>工厂创建<a href="../../../javax/xml/validation/SchemaFactory.html" title="javax.xml.validation中的类"><code>SchemaFactory</code></a></span>
</div> </td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../javax/xml/validation/TypeInfoProvider.html" title="class in javax.xml.validation">TypeInfoProvider</a></td>
<td class="colLast">
<div class="block">
<span>该类提供对由<a href="../../../javax/xml/validation/ValidatorHandler.html" title="javax.xml.validation中的类"><code>ValidatorHandler</code></a>确定的类型信息的<a href="../../../javax/xml/validation/ValidatorHandler.html" title="javax.xml.validation中的类">访问</a></span>
</div> </td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../javax/xml/validation/Validator.html" title="class in javax.xml.validation">Validator</a></td>
<td class="colLast">
<div class="block">
<span>根据<code>Schema</code>检查XML文档的<a href="../../../javax/xml/validation/Schema.html" title="javax.xml.validation中的类">处理器</a></span>
</div> </td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../javax/xml/validation/ValidatorHandler.html" title="class in javax.xml.validation">ValidatorHandler</a></td>
<td class="colLast">
<div class="block">
流式验证器适用于SAX流。
</div> </td>
</tr>
</tbody>
</table> </li>
<li class="blockList">
<table border="0" cellpadding="3" cellspacing="0" class="typeSummary" summary="Error Summary table, listing errors, and an explanation">
<caption>
<span>Error Summary</span>
<span class="tabEnd"> </span>
</caption>
<tbody>
<tr>
<th class="colFirst" scope="col">Error</th>
<th class="colLast" scope="col">描述</th>
</tr>
</tbody>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../javax/xml/validation/SchemaFactoryConfigurationError.html" title="class in javax.xml.validation">SchemaFactoryConfigurationError</a></td>
<td class="colLast">
<div class="block">
当存在具有Schema工厂的配置问题时抛出。
</div> </td>
</tr>
</tbody>
</table> </li>
</ul>
<a name="package.description">
<!-- --> </a>
<h2 title="Package javax.xml.validation Description">Package javax.xml.validation Description</h2>
<div class="block">
<p> <span>此软件包提供了一个用于验证XML文档的API。</span> <span><em>验证</em>是验证XML文档是指定的XML <em>模式</em>的实例的过程。</span> <span>XML模式定义其实例文档将表示的内容模型也称为<em>语法</em><em>词汇</em> )。</span> </p>
<p> <span>有许多流行的技术可用于创建XML模式。</span> <span>一些最受欢迎的包括:</span> </p>
<ul>
<li> <span><strong>文档类型定义DTD</strong> - XML的内置模式语言。</span> </li>
<li> <span><strong><a href="http://www.w3.org/XML/Schema">W3C XML Schema (WXS)</a></strong> - 面向对象的XML模式语言。</span> <span>WXS还提供了一种用于约束XML文档的字符数据的类型系统。</span> <span>WXS由<a href="http://www.w3.org">World Wide Web Consortium (W3C)维护</a> 是W3C推荐即批准的W3C标准规范</span> </li>
<li> <span><strong><a href="http://www.relaxng.org">RELAX NG (RNG)</a></strong> - 基于模式的用户友好的XML模式语言。</span> <span>RNG模式也可以使用类型来约束XML字符数据。</span> <span>RNG由<a href="http://www.oasis-open.org">Organization for the Advancement of Structured Information Standards (OASIS)维护</a> 均为OASIS和<a href="http://www.iso.org">ISO (International Organization for Standardization)</a>标准。</span> </li>
<li> <span><strong><a href="http://www.schematron.com/">Schematron</a></strong> - 基于规则的XML模式语言。</span> <span>而DTDWXS和RNG旨在表达内容模型的结构Schematron旨在强制使用其他模式语言来表达困难或不可能的单个规则。</span> <span>Schematron旨在补充以前述结构模式语言编写的模式。</span> <span>Schematron正在成为ISO标准。</span> </li>
</ul>
<p> <span>以前版本的JAXP支持验证作为XML解析器的特征<a href="../../../javax/xml/parsers/SAXParser.html" title="javax.xml.parsers中的类"><code>SAXParser</code></a><a href="../../../javax/xml/parsers/DocumentBuilder.html" title="javax.xml.parsers中的类"><code>DocumentBuilder</code></a>实例表示。</span> </p>
<p> <span>JAXP验证API将实例文档的验证与XML文档的解析分离。</span> <span>这是有利于几个原因,其中一些是:</span> </p>
<ul>
<li> <span><strong>支持额外的架构langauges。</strong></span> <span>从JDK 1.5开始两个最受欢迎的JAXP解析器实现Crimson和Xerces仅支持可用的XML模式语言的一部分。</span> <span>验证API提供了一种标准机制通过该机制应用程序可以利用支持附加模式语言的专业化验证库。</span> </li>
<li> <span><strong>XML实例和模式的简单运行时耦合。</strong></span> <span>指定用于使用JAXP解析器进行验证的模式的位置可能会令人困惑。</span> <span>验证API使此过程变得简单参见下面的<a href="#example-1">example</a> )。</span> </li>
</ul>
<p> <span><a name="example-1"><strong>Usage example</strong>.</a>以下示例演示如何使用Validation API验证XML文档为了可读性未显示某些异常处理</span> </p>
<pre> <span>// 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!
}</span> </pre>
<p> <span>JAXP解析API已经与验证API集成。</span> <span>应用程序可以创建具有<a href="../../../javax/xml/validation/Schema.html" title="javax.xml.validation中的类">验证</a> API的<code>Schema</code>,并使用<a href="../../../javax/xml/parsers/DocumentBuilderFactory.html#setSchema-javax.xml.validation.Schema-"><code>DocumentBuilderFactory.setSchema(Schema)</code></a><a href="../../../javax/xml/parsers/SAXParserFactory.html#setSchema-javax.xml.validation.Schema-"><code>SAXParserFactory.setSchema(Schema)</code></a>方法将其与<a href="../../../javax/xml/parsers/DocumentBuilderFactory.html" title="javax.xml.parsers中的类"><code>DocumentBuilderFactory</code></a><a href="../../../javax/xml/parsers/SAXParserFactory.html" title="javax.xml.parsers中的类"><code>SAXParserFactory</code></a>实例相关<a href="../../../javax/xml/parsers/DocumentBuilderFactory.html#setSchema-javax.xml.validation.Schema-"></a></span> <span><strong>您不应</strong>同时设置模式并在解析器工厂调用<code>setValidating(true)</code></span> <span>前一种技术将导致解析器使用新的验证API;</span> <span>后者将使解析器使用自己的内部验证设施。</span> <span><strong>同时打开这两个选项将导致冗余行为或错误条件。</strong></span> </p>
</div>
</div>