接口 | 描述 |
---|---|
AttributeList | Deprecated
此接口已被 Attributes SAX2接口所取代,其中包括命名空间的支持。
|
Attributes |
用于XML属性列表的接口。
|
ContentHandler |
接收文档的逻辑内容的通知。
|
DocumentHandler | Deprecated
此接口已被 ContentHandler SAX2接口所取代,其中包括命名空间的支持。
|
DTDHandler |
获得基本DTD相关事件的通知。
|
EntityResolver |
解析实体的基本接口。
|
ErrorHandler |
萨克斯错误处理程序的基本界面。
|
Locator |
关联的SAX事件和文档位置界面。
|
Parser | Deprecated
此接口已被 XMLReader SAX2接口所取代,其中包括命名空间的支持。
|
XMLFilter |
用于XML筛选器的接口。
|
XMLReader |
阅读XML文档使用回调接口。
|
类 | 描述 |
---|---|
HandlerBase | Deprecated
这类作品与过时的 DocumentHandler 接口。
|
InputSource |
用于XML实体的单个输入源。
|
异常 | 描述 |
---|---|
SAXException |
把一个一般的萨克斯错误或警告。
|
SAXNotRecognizedException |
未识别的标识符的异常类。
|
SAXNotSupportedException |
不支持的操作的异常类。
|
SAXParseException |
封装一个XML解析错误或警告。
|
这个包提供了核心的SAX。某些SAX1 API使用命名空间的意识鼓励融入新的应用设计和现有基础设施的维护。
看到http://www.saxproject.org有关SAX的更多信息。
一个SAX2的本质特征在于它附加的功能标记可用于检查和可能修改解析模式,如验证特定的模式。因为功能是确定的(绝对)的URI,任何人都可以定义等功能。目前定义的标准功能URI前缀http://xml.org/sax/features/
之前如validation
标识符。打开或关闭使用setfeature特征。这些标准标识符是:
Feature ID | Access | Default | 描述 |
---|---|---|---|
external-general-entities | read/write | unspecified | Reports whether this parser processes external general entities; always true if validating. |
external-parameter-entities | read/write | unspecified | Reports whether this parser processes external parameter entities; always true if validating. |
is-standalone | (parsing) read-only, (not parsing) none | not applicable | May be examined only during a parse, after the startDocument() callback has been completed; read-only. The value is true if the document specified standalone="yes" in its XML declaration, and otherwise is false. |
lexical-handler/parameter-entities | read/write | unspecified | A value of "true" indicates that the LexicalHandler will report the beginning and end of parameter entities. |
namespaces | read/write | true | A value of "true" indicates namespace URIs and unprefixed local names for element and attribute names will be available. |
namespace-prefixes | read/write | false | A value of "true" indicates that XML qualified names (with prefixes) and attributes (including xmlns* attributes) will be available. |
resolve-dtd-uris | read/write | true | A value of "true" indicates that system IDs in declarations will be absolutized (relative to their base URIs) before reporting. (That is the default behavior for all SAX2 XML parsers.) A value of "false" indicates those IDs will not be absolutized; parsers will provide the base URI from Locator.getSystemId(). This applies to system IDs passed in
|
string-interning | read/write | unspecified | Has a value of "true" if all XML names (for elements, prefixes, attributes, entities, notations, and local names), as well as Namespace URIs, will have been interned using java.lang.String.intern. This supports fast testing of equality/inequality against string constants, rather than forcing slower calls to String.equals(). |
unicode-normalization-checking | read/write | false | Controls whether the parser reports Unicode normalization errors as described in section 2.13 and Appendix B of the XML 1.1 Recommendation. If true, Unicode normalization errors are reported using the ErrorHandler.error() callback. Such errors are not fatal in themselves (though, obviously, other Unicode-related encoding errors may be). |
use-attributes2 | read-only | not applicable | Returns "true" if the Attributes objects passed by this parser in ContentHandler.startElement() implement the org.xml.sax.ext.Attributes2 interface. That interface exposes additional DTD-related information, such as whether the attribute was specified in the source text rather than defaulted. |
use-locator2 | read-only | not applicable | Returns "true" if the Locator objects passed by this parser in ContentHandler.setDocumentLocator() implement the org.xml.sax.ext.Locator2 interface. That interface exposes additional entity information, such as the character encoding and XML version used. |
use-entity-resolver2 | read/write | true | Returns "true" if, when setEntityResolver is given an object implementing the org.xml.sax.ext.EntityResolver2 interface, those new methods will be used. Returns "false" to indicate that those methods will not be used. |
validation | read/write | unspecified | Controls whether the parser is reporting all validity errors; if true, all external entities will be read. |
xmlns-uris | read/write | false | Controls whether, when the namespace-prefixes feature is set, the parser treats namespace declaration attributes as being in the http://www.w3.org/2000/xmlns/ namespace. By default, SAX2 conforms to the original "Namespaces in XML" Recommendation, which explicitly states that such attributes are not in any namespace. Setting this optional flag to "true" makes the SAX2 events conform to a later backwards-incompatible revision of that recommendation, placing those attributes in a namespace. |
xml-1.1 | read-only | not applicable | Returns "true" if the parser supports both XML 1.1 and XML 1.0. Returns "false" if the parser supports only XML 1.0. |
为命名空间和命名空间前缀属性的默认值的支持是必需的。支持任何其他功能标志是完全可选的。
默认值没有指定的SAX2,每个XmlReader实现指定其默认值,或者可以选择不暴露特征标志。除非在这里指定,否则实现可能支持改变这些标准特征标志的当前值,但不能在解析时改变这些标准的当前值。
对于被描述为对象的解析器接口特性,定义了一个单独的命名空间。此命名空间中的对象又是由URI和标准属性URI前缀http://xml.org/sax/properties/
之前如lexical-handler
或dom-node
标识符。使用setproperty()管理这些特性。这些标识符是:
Property ID | 描述 |
---|---|
declaration-handler | Used to see most DTD declarations except those treated as lexical ("document element name is ...") or which are mandatory for all SAX parsers (DTDHandler). The Object must implement org.xml.sax.ext.DeclHandler. |
document-xml-version | May be examined only during a parse, after the startDocument() callback has been completed; read-only. This property is a literal string describing the actual XML version of the document, such as "1.0" or "1.1". |
dom-node | For "DOM Walker" style parsers, which ignore their parser.parse() parameters, this is used to specify the DOM (sub)tree being walked by the parser. The Object must implement the org.w3c.dom.Node interface. |
lexical-handler | Used to see some syntax events that are essential in some applications: comments, CDATA delimiters, selected general entity inclusions, and the start and end of the DTD (and declaration of document element name). The Object must implement org.xml.sax.ext.LexicalHandler. |
xml-string | Readable only during a parser callback, this exposes a TBS chunk of characters responsible for the current event. |
这些标准的所有属性都是可选的;在实现不需要支持他们。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.