Most visited

Recently visited

Added in API level 1

DefaultHandler2

public class DefaultHandler2
extends DefaultHandler implements LexicalHandler, DeclHandler, EntityResolver2

java.lang.Object
   ↳ org.xml.sax.helpers.DefaultHandler
     ↳ org.xml.sax.ext.DefaultHandler2


此类扩展SAX2基本处理程序类,以支持SAX2 LexicalHandlerDeclHandler ,并EntityResolver2扩展。 除了覆盖最初的SAX1 resolveEntity()方法外,添加的处理程序方法只是返回。 子程序员可以逐个方法地覆盖所有内容。

This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY.

注意:这个类可能已经知道 ContentHandler.setDocumentLocator()调用可能会被传递给一个 Locator2对象,并且 ContentHandler.startElement()调用可能会被传递给一个 Attributes2对象。

Summary

Public constructors

DefaultHandler2()

构造一个忽略所有分析事件的处理程序。

Public methods

void attributeDecl(String eName, String aName, String type, String mode, String value)

报告属性类型声明。

void comment(char[] ch, int start, int length)

在文档的任何位置报告XML注释。

void elementDecl(String name, String model)

报告元素类型声明。

void endCDATA()

报告CDATA部分的结尾。

void endDTD()

报告DTD声明的结束。

void endEntity(String name)

报告实体的结束。

void externalEntityDecl(String name, String publicId, String systemId)

报告解析的外部实体声明。

InputSource getExternalSubset(String name, String baseURI)

告诉解析器,如果在文档文本中没有声明外部子集,则不应使用任何子集。

void internalEntityDecl(String name, String value)

报告内部实体声明。

InputSource resolveEntity(String publicId, String systemId)

用空实体名称和基URI调用 EntityResolver2.resolveEntity()

InputSource resolveEntity(String name, String publicId, String baseURI, String systemId)

告诉解析器针对baseURI解析systemId并从该生成的绝对URI中读取实体文本。

void startCDATA()

报告CDATA部分的开始。

void startDTD(String name, String publicId, String systemId)

报告DTD声明的开始(如果有的话)。

void startEntity(String name)

报告一些内部和外部XML实体的开始。

Inherited methods

From class org.xml.sax.helpers.DefaultHandler
From class java.lang.Object
From interface org.xml.sax.EntityResolver
From interface org.xml.sax.DTDHandler
From interface org.xml.sax.ContentHandler
From interface org.xml.sax.ErrorHandler
From interface org.xml.sax.ext.LexicalHandler
From interface org.xml.sax.ext.DeclHandler
From interface org.xml.sax.ext.EntityResolver2

Public constructors

DefaultHandler2

Added in API level 1
DefaultHandler2 ()

构造一个忽略所有分析事件的处理程序。

Public methods

attributeDecl

Added in API level 1
void attributeDecl (String eName, 
                String aName, 
                String type, 
                String mode, 
                String value)

报告属性类型声明。

只有属性的有效(第一次)声明才会被报告。 该类型将是字符串“CDATA”,“ID”,“IDREF”,“IDREFS”,“NMTOKEN”,“NMTOKENS”,“ENTITY”,“ENTITIES”,带分隔符“|”的括号标记组之一。 并删除所有空格或单词“NOTATION”后面跟着一个空格,后面跟着一个删除了所有空格的带括号的标记组。

该值将作为报告给应用程序的值,适当标准化并扩展实体和字符引用。

Parameters
eName String: The name of the associated element.
aName String: The name of the attribute.
type String: A string representing the attribute type.
mode String: A string representing the attribute defaulting mode ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
value String: A string representing the attribute's default value, or null if there is none.
Throws
SAXException

comment

Added in API level 1
void comment (char[] ch, 
                int start, 
                int length)

在文档的任何位置报告XML注释。

此回调将用于文档元素内部或外部的注释,包括外部DTD子集(如果已阅读)中的注释。 DTD中的注释必须正确嵌套在start / endDTD和start / endEntity事件中(如果使用的话)。

Parameters
ch char: An array holding the characters in the comment.
start int: The starting position in the array.
length int: The number of characters to use from the array.
Throws
SAXException

elementDecl

Added in API level 1
void elementDecl (String name, 
                String model)

报告元素类型声明。

内容模型将包含字符串“EMPTY”,字符串“ANY”或括号组,可选地后跟一个事件指示符。 该模型将被标准化,以便所有参数实体完全解析并删除所有空白,并包含括号。 其他规范化(如去除多余的括号或简化事件指示符)由解析器自行决定。

Parameters
name String: The element type name.
model String: The content model as a normalized string.
Throws
SAXException

endCDATA

Added in API level 1
void endCDATA ()

报告CDATA部分的结尾。

Throws
SAXException

endDTD

Added in API level 1
void endDTD ()

报告DTD声明的结束。

此方法旨在报告DOCTYPE声明的结束; 如果文档没有DOCTYPE声明,则不会调用此方法。

Throws
SAXException

endEntity

Added in API level 1
void endEntity (String name)

报告实体的结束。

Parameters
name String: The name of the entity that is ending.
Throws
SAXException

externalEntityDecl

Added in API level 1
void externalEntityDecl (String name, 
                String publicId, 
                String systemId)

报告解析的外部实体声明。

只报告每个实体的有效(第一)声明。

如果系统标识符是URL,则解析器必须在将其传递给应用程序之前将其完全解析。

Parameters
name String: The name of the entity. If it is a parameter entity, the name will begin with '%'.
publicId String: The entity's public identifier, or null if none was given.
systemId String: The entity's system identifier.
Throws
SAXException

getExternalSubset

Added in API level 1
InputSource getExternalSubset (String name, 
                String baseURI)

告诉解析器,如果在文档文本中没有声明外部子集,则不应使用任何子集。

Parameters
name String: Identifies the document root element. This name comes from a DOCTYPE declaration (where available) or from the actual root element. The parameter is ignored.
baseURI String: The document's base URI, serving as an additional hint for selecting the external subset. This is always an absolute URI, unless it is null because the XMLReader was given an InputSource without one. The parameter is ignored.
Returns
InputSource null (always).
Throws
SAXException Any SAX exception, possibly wrapping another exception.
IOException Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.

internalEntityDecl

Added in API level 1
void internalEntityDecl (String name, 
                String value)

报告内部实体声明。

只报告每个实体的有效(第一)声明。 值中的所有参数实体将被展开,但一般实体不会。

Parameters
name String: The name of the entity. If it is a parameter entity, the name will begin with '%'.
value String: The replacement text of the entity.
Throws
SAXException

resolveEntity

Added in API level 1
InputSource resolveEntity (String publicId, 
                String systemId)

用空实体名称和基URI调用EntityResolver2.resolveEntity() 您只需重写该方法即可使用此类。

Parameters
publicId String: The public identifier of the external entity being referenced (normalized as required by the XML specification), or null if none was supplied.
systemId String: The system identifier of the external entity being referenced; either a relative or absolute URI. This is never null when invoked by a SAX2 parser; only declared entities, and any external subset, are resolved by such parsers.
Returns
InputSource An InputSource object describing the new input source.
Throws
SAXException Any SAX exception, possibly wrapping another exception.
IOException Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.

resolveEntity

Added in API level 1
InputSource resolveEntity (String name, 
                String publicId, 
                String baseURI, 
                String systemId)

告诉解析器针对baseURI解析systemId并从该生成的绝对URI中读取实体文本。 请注意,因为较旧的DefaultHandler.resolveEntity() ,方法被重写以调用此方法,所以有时可以使用null 名称baseURI调用此方法,并且systemId已经绝对化。

Parameters
name String: Identifies the external entity being resolved. Either "[dtd]" for the external subset, or a name starting with "%" to indicate a parameter entity, or else the name of a general entity. This is never null when invoked by a SAX2 parser.
publicId String: The public identifier of the external entity being referenced (normalized as required by the XML specification), or null if none was supplied.
baseURI String: The URI with respect to which relative systemIDs are interpreted. This is always an absolute URI, unless it is null (likely because the XMLReader was given an InputSource without one). This URI is defined by the XML specification to be the one associated with the "<" starting the relevant declaration.
systemId String: The system identifier of the external entity being referenced; either a relative or absolute URI. This is never null when invoked by a SAX2 parser; only declared entities, and any external subset, are resolved by such parsers.
Returns
InputSource An InputSource object describing the new input source.
Throws
SAXException Any SAX exception, possibly wrapping another exception.
IOException Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.

startCDATA

Added in API level 1
void startCDATA ()

报告CDATA部分的开始。

The contents of the CDATA section will be reported through the regular characters event; this event is intended only to report the boundary.

Throws
SAXException

startDTD

Added in API level 1
void startDTD (String name, 
                String publicId, 
                String systemId)

报告DTD声明的开始(如果有的话)。

此方法旨在报告DOCTYPE声明的开始; 如果文档没有DOCTYPE声明,则不会调用此方法。

通过DTDHandlerDeclHandler事件报告的所有声明必须出现在startDTD和endDTD事件之间。 假定声明属于内部DTD子集,除非它们出现在startEntityendEntity事件之间。 来自DTD的注释和处理指令也应该以startDTD和endDTD事件之间的原始顺序(逻辑)出现; 但是,它们不需要出现在相对于DTDHandler或DeclHandler事件的正确位置。

请注意,start / endDTD事件将出现在ContentHandler的start / endDocument事件中,并且在第一个 startElement事件之前。

Parameters
name String: The document type name.
publicId String: The declared public identifier for the external DTD subset, or null if none was declared.
systemId String: The declared system identifier for the external DTD subset, or null if none was declared. (Note that this is not resolved against the document base URI.)
Throws
SAXException

startEntity

Added in API level 1
void startEntity (String name)

报告一些内部和外部XML实体的开始。

参数实体(包括外部DTD子集)的报告是可选的,报告LexicalHandler事件的SAX2驱动程序可能不会实现它; 您可以使用http://xml.org/sax/features/lexical-handler/parameter-entities功能来查询或控制参数实体的报告。

常规实体以其常规名称报告,参数实体在其名称前加'%',而外部DTD子集具有伪实体名称“[dtd]”。

当SAX2驱动程序提供这些事件时,所有其他事件必须正确嵌套在开始/结束实体事件中。 没有额外的要求来自DeclHandlerDTDHandler事件被正确订购。

请注意,跳过的实体将通过 skippedEntity事件进行报告,该事件是ContentHandler界面的一部分。

由于SAX使用的流式事件模型,在任何情况下都不能报告一些实体边界:

  • general entities within attribute values
  • parameter entities within declarations

这些将被默默扩大,并没有指出原始实体边界在哪里。

还要注意,字符引用的边界(它们实际上并不是真正的实体)不会被报告。

所有开始/结束实体事件必须正确嵌套。

Parameters
name String: The name of the entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be "[dtd]".
Throws
SAXException

Hooray!