public class HandlerBase
extends Object implements EntityResolver, DTDHandler, DocumentHandler, ErrorHandler
| java.lang.Object | |
| org.xml.sax.HandlerBase | |
此类已在API级别1中弃用。
该类适用于已弃用的DocumentHandler界面。 它已被SAX2 DefaultHandler类取代。
处理程序的默认基类。
This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY. See http://www.saxproject.org for further information.
该类实现四个SAX1接口的默认行为:EntityResolver,DTDHandler,DocumentHandler和ErrorHandler。 它现在已经过时,但包含在SAX2中以支持传统的SAX1应用程序。 SAX2应用程序应该使用DefaultHandler类。
应用程序编写者可以在需要仅实现接口的一部分时扩展此类; 解析器编写者可以实例化这个类,以便在应用程序没有提供它自己的时候提供默认的处理程序。
请注意,此类的使用是可选的。
Public constructors |
|
|---|---|
HandlerBase() |
|
公共方法(Public methods) |
|
|---|---|
void |
characters(char[] ch, int start, int length) 接收元素内部字符数据的通知。 |
void |
endDocument() 接收文档结尾的通知。 |
void |
endElement(String name) 接收元素结束的通知。 |
void |
error(SAXParseException e) 接收可恢复解析器错误的通知。 |
void |
fatalError(SAXParseException e) 报告致命的XML解析错误。 |
void |
ignorableWhitespace(char[] ch, int start, int length) 接收元素内容中可忽略空白的通知。 |
void |
notationDecl(String name, String publicId, String systemId) 接收记录声明的通知。 |
void |
processingInstruction(String target, String data) 接收处理指令的通知。 |
InputSource |
resolveEntity(String publicId, String systemId) 解决外部实体。 |
void |
setDocumentLocator(Locator locator) 接收文档事件的定位器对象。 |
void |
startDocument() 接收文档开始的通知。 |
void |
startElement(String name, AttributeList attributes) 接收元素开始的通知。 |
void |
unparsedEntityDecl(String name, String publicId, String systemId, String notationName) 接收未解析实体声明的通知。 |
void |
warning(SAXParseException e) 接收解析器警告的通知。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
org.xml.sax.EntityResolver
|
|
org.xml.sax.DTDHandler
|
|
org.xml.sax.DocumentHandler
|
|
org.xml.sax.ErrorHandler
|
|
void characters (char[] ch,
int start,
int length)
接收元素内部字符数据的通知。
默认情况下,什么都不做。 应用程序编写者可以重写此方法以对每个字符数据块执行特定操作(例如将数据添加到节点或缓冲区,或将其打印到文件中)。
| 参数(Parameters) | |
|---|---|
ch |
char: The characters. |
start |
int: The start position in the character array. |
length |
int: The number of characters to use from the character array. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
也可以看看:
void endDocument ()
接收文档结尾的通知。
默认情况下,什么都不做。 应用程序编写者可以在子类中重写此方法,以便在文档的开始处执行特定的操作(例如完成树或关闭输出文件)。
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
也可以看看:
void endElement (String name)
接收元素结束的通知。
默认情况下,什么都不做。 应用程序编写者可以在子类中重写此方法,以便在每个元素的末尾执行特定操作(例如完成树节点或将输出写入文件)。
| 参数(Parameters) | |
|---|---|
name |
String: the element name |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
也可以看看:
void error (SAXParseException e)
接收可恢复解析器错误的通知。
默认实现什么都不做。 应用程序编写者可以在子类中重写此方法,以针对每个错误采取特定的操作,例如将消息插入日志文件或将其打印到控制台。
| 参数(Parameters) | |
|---|---|
e |
SAXParseException: The warning information encoded as an exception. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
void fatalError (SAXParseException e)
报告致命的XML解析错误。
默认实现抛出一个SAXParseException。 如果应用程序编写者需要针对每个致命错误采取特定操作(例如将所有错误收集到单个报告中),则可以在子类中重写此方法:在任何情况下,应用程序必须在调用此方法时停止所有常规处理,因为文档不再可靠,解析器可能不再报告解析事件。
| 参数(Parameters) | |
|---|---|
e |
SAXParseException: The error information encoded as an exception. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
void ignorableWhitespace (char[] ch,
int start,
int length)
接收元素内容中可忽略空白的通知。
默认情况下,什么都不做。 应用程序编写者可以重写此方法,对每个可忽略的空白块(例如将数据添加到节点或缓冲区,或将其打印到文件)采取特定的操作。
| 参数(Parameters) | |
|---|---|
ch |
char: The whitespace characters. |
start |
int: The start position in the character array. |
length |
int: The number of characters to use from the character array. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
void notationDecl (String name, String publicId, String systemId)
接收记录声明的通知。
By default, do nothing. Application writers may override this method in a subclass if they wish to keep track of the notations declared in a document.
| 参数(Parameters) | |
|---|---|
name |
String: The notation name. |
publicId |
String: The notation public identifier, or null if not available. |
systemId |
String: The notation system identifier. |
void processingInstruction (String target, String data)
接收处理指令的通知。
默认情况下,什么都不做。 应用程序编写者可以在子类中重写此方法,以便为每个处理指令采取特定的操作,例如设置状态变量或调用其他方法。
| 参数(Parameters) | |
|---|---|
target |
String: The processing instruction target. |
data |
String: The processing instruction data, or null if none is supplied. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
InputSource resolveEntity (String publicId, String systemId)
解决外部实体。
始终返回null,以便解析器将使用XML文档中提供的系统标识符。 此方法实现SAX默认行为:应用程序编写者可以在子类中覆盖它以执行特殊翻译,例如目录查找或URI重定向。
| 参数(Parameters) | |
|---|---|
publicId |
String: The public identifer, or null if none is available. |
systemId |
String: The system identifier provided in the XML document. |
| 返回(Returns) | |
|---|---|
InputSource |
The new input source, or null to require the default behaviour. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
void setDocumentLocator (Locator locator)
接收文档事件的定位器对象。
By default, do nothing. Application writers may override this method in a subclass if they wish to store the locator for use with other document events.
| 参数(Parameters) | |
|---|---|
locator |
Locator: A locator for all SAX document events. |
void startDocument ()
接收文档开始的通知。
默认情况下,什么都不做。 应用程序编写者可以在子类中重写此方法,以便在文档的开头执行特定操作(例如分配树的根节点或创建输出文件)。
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
也可以看看:
void startElement (String name, AttributeList attributes)
接收元素开始的通知。
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).
| 参数(Parameters) | |
|---|---|
name |
String: The element type name. |
attributes |
AttributeList: The specified or defaulted attributes. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |
void unparsedEntityDecl (String name, String publicId, String systemId, String notationName)
接收未解析实体声明的通知。
默认情况下,什么都不做。 应用程序编写者可以在子类中重写此方法以跟踪文档中声明的未解析的实体。
| 参数(Parameters) | |
|---|---|
name |
String: The entity name. |
publicId |
String: The entity public identifier, or null if not available. |
systemId |
String: The entity system identifier. |
notationName |
String: The name of the associated notation. |
void warning (SAXParseException e)
接收解析器警告的通知。
默认实现什么都不做。 应用程序编写者可以在子类中重写此方法,以针对每个警告采取特定的操作,例如将消息插入日志文件或将其打印到控制台。
| 参数(Parameters) | |
|---|---|
e |
SAXParseException: The warning information encoded as an exception. |
| 抛出异常(Throws) | |
|---|---|
SAXException |
Any SAX exception, possibly wrapping another exception. |