uTools-Manuals/docs/java/org/xml/sax/EntityResolver.html

158 lines
8.2 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">
<div class="subTitle">
compact2, compact3
</div>
<div class="subTitle">
org.xml.sax
</div>
<h2 class="title" title="Interface EntityResolver">Interface EntityResolver</h2>
</div><div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>
All Known Subinterfaces:
</dt>
<dd>
<span><a href="../../../org/xml/sax/ext/EntityResolver2.html" title="org.xml.sax.ext中的接口">EntityResolver2</a></span>
</dd>
</dl>
<dl>
<dt>
所有已知实现类:
</dt>
<dd>
<span><a href="../../../org/xml/sax/helpers/DefaultHandler.html" title="org.xml.sax.helpers中的类">DefaultHandler</a> <a href="../../../org/xml/sax/ext/DefaultHandler2.html" title="org.xml.sax.ext中的类">DefaultHandler2</a> <a href="../../../org/xml/sax/HandlerBase.html" title="在org.xml.sax中的类">HandlerBase</a> <a href="../../../org/xml/sax/helpers/XMLFilterImpl.html" title="org.xml.sax.helpers中的类">XMLFilterImpl</a></span>
</dd>
</dl>
<hr/> <br/> <pre>public interface <span class="typeNameLabel">EntityResolver</span></pre>
<div class="block">
<span>解决实体的基本界面。</span>
<blockquote>
<span><em>This module, both source code and documentation, is in the Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> See <a href="http://www.saxproject.org">http://www.saxproject.org</a> for further information.</span>
</blockquote>
<p> <span>如果SAX应用程序需要为外部实体实现定制处理则必须实现该接口并使用<a href="../../../org/xml/sax/XMLReader.html#setEntityResolver-org.xml.sax.EntityResolver-"><code>setEntityResolver</code></a>方法向SAX驱动程序注册一个实例。</span> </p>
<p> <span>然后XML读取器将允许应用程序在包含它们之前拦截任何外部实体包括外部DTD子集和外部参数实体如果有的话</span> </p>
<p> <span>许多SAX应用程序不需要实现此接口但是对于从数据库或其他专门的输入源构建XML文档的应用程序或者使用URL以外的URI类型的应用程序这将非常有用。</span> </p>
<p> <span>以下解析器将为应用程序提供具有系统标识符“http://www.myhost.com/today”的实体的特殊字符流</span> </p>
<pre> <span>import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
public class MyResolver implements EntityResolver {
public InputSource resolveEntity (String publicId, String systemId)
{
if (systemId.equals("http://www.myhost.com/today")) {
// return a special input source
MyReader reader = new MyReader();
return new InputSource(reader);
} else {
// use the default behaviour
return null;
}
}
}</span> </pre>
<p> <span>该应用程序还可以使用此接口将系统标识符重定向到本地URI或查找目录中的替换可能通过使用公共标识符</span> </p>
</div>
<dl>
<dt>
<span class="simpleTagLabel">从以下版本开始:</span>
</dt>
<dd>
SAX 1.0
</dd>
<dt>
<span class="seeLabel">另请参见:</span>
</dt>
<dd>
<span><a href="../../../org/xml/sax/XMLReader.html#setEntityResolver-org.xml.sax.EntityResolver-"><code>XMLReader.setEntityResolver(org.xml.sax.EntityResolver)</code></a> <a href="../../../org/xml/sax/InputSource.html" title="在org.xml.sax中的类"><code>InputSource</code></a></span>
</dd>
</dl> </li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- --> </a> <h3>方法摘要</h3>
<table border="0" cellpadding="3" cellspacing="0" class="memberSummary" summary="Method Summary table, listing methods, and an explanation">
<caption>
<span class="activeTableTab" id="t0"><span>所有方法</span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t2"><span><a href="javascript:show(2);">接口方法</a></span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t3"><span><a href="javascript:show(4);">抽象方法</a></span><span class="tabEnd"> </span></span>
</caption>
<tbody>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor" id="i0">
<td class="colFirst"><code><a href="../../../org/xml/sax/InputSource.html" title="class in org.xml.sax">InputSource</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../org/xml/sax/EntityResolver.html#resolveEntity-java.lang.String-java.lang.String-">resolveEntity</a></span>(<a href="../../../java/lang/String.html" title="class in java.lang">String</a> publicId, <a href="../../../java/lang/String.html" title="class in java.lang">String</a> systemId)</code>
<div class="block">
允许应用程序解析外部实体。
</div> </td>
</tr>
</tbody>
</table> </li>
</ul> </li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- --> </a> <h3>方法详细信息</h3> <a name="resolveEntity-java.lang.String-java.lang.String-">
<!-- --> </a>
<ul class="blockListLast">
<li class="blockList"> <h4>resolveEntity</h4> <pre><a href="../../../org/xml/sax/InputSource.html" title="class in org.xml.sax">InputSource</a> resolveEntity(<a href="../../../java/lang/String.html" title="class in java.lang">String</a> publicId,
<a href="../../../java/lang/String.html" title="class in java.lang">String</a> systemId)
throws <a href="../../../org/xml/sax/SAXException.html" title="class in org.xml.sax">SAXException</a>,
<a href="../../../java/io/IOException.html" title="class in java.io">IOException</a></pre>
<div class="block">
<span>允许应用程序解析外部实体。</span>
<p> <span>解析器将在打开除顶层文档实体之外的任何外部实体时调用此方法。</span> <span>这样的实体包括DTD内部引用的外部DTD子集和外部参数实体在这两种情况下只有在解析器读取外部参数实体时以及在文档元素中引用的外部通用实体如果解析器读取外部一般实体</span> <span>应用程序可以请求解析器定位实体本身使用替代URI或者使用应用程序提供的数据作为字符或字节输入流</span> </p>
<p> <span>应用程序编写者可以使用此方法将外部系统标识符重定向到安全和/或本地URI查找目录中的公共标识符或从数据库或其他输入源包括例如对话框读取实体</span> <span>XML和SAX都不指定使用公共或系统ID来解决资源的首选策略。</span> <span>但是SAX指定如何解释此方法返回的任何InputSource如果没有返回任何InputSource则系统ID将被解除引用为URL。</span> </p>
<p> <span>如果系统标识符是URL则SAX解析器必须在将其报告给应用程序之前完全解析。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<code>publicId</code> - 被引用的外部实体的公共标识符如果没有提供则为null。
</dd>
<dd>
<code>systemId</code> - 被引用的外部实体的系统标识符。
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
描述新输入源的InputSource对象或者是null以请求解析器打开与系统标识符的常规URI连接。
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../../org/xml/sax/SAXException.html" title="class in org.xml.sax">SAXException</a></code> - 任何SAX异常可能包括另一个异常。
</dd>
<dd>
<code><a href="../../../java/io/IOException.html" title="class in java.io">IOException</a></code> - Java特定的IO异常可能是为InputSource创建一个新的InputStream或Reader的结果。
</dd>
<dt>
<span class="seeLabel">另请参见:</span>
</dt>
<dd>
<a href="../../../org/xml/sax/InputSource.html" title="class in org.xml.sax"><code>InputSource</code></a>
</dd>
</dl> </li>
</ul> </li>
</ul> </li>
</ul>
</div>
</div>