模块  java.xml

Package org.xml.sax

提供核心SAX API。 不推荐使用某些SAX1 API以鼓励将命名空间感知集成到新应用程序的设计和现有基础架构的维护中。

有关SAX的更多信息,请参见http://www.saxproject.org

SAX2标准功能标志

SAX2的一个基本特征是它添加了功能标志,可用于检查和修改解析器模式,特别是验证等模式。 由于功能由(绝对)URI标识,因此任何人都可以定义此类功能。 当前定义的标准功能的URI具有前缀http://xml.org/sax/features/作为这样一个标识符之前validation 使用setFeature打开或关闭功能。 这些标准标识符是:

Standard Features Feature ID Access Default Description 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
  • DTDHandler.notationDecl(),
  • DTDHandler.unparsedEntityDecl(), and
  • DeclHandler.externalEntityDecl().
It does not apply to EntityResolver.resolveEntity(), which is not used to report declarations, or to LexicalHandler.startDTD(), which already provides the non-absolutized URI. 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实现都指定其默认值,或者可以选择不公开功能标志。 除非此处另有说明,否则实现可能支持更改这些标准功能标志的当前值,但在解析时则不支持。

SAX2标准处理程序和属性ID

对于描述为对象的解析器接口特性,定义了单独的命名空间。 在该命名空间中的对象由URI再次识别,并且标准属性的URI具有前缀http://xml.org/sax/properties/作为这样的识别符之前lexical-handlerdom-node 使用setProperty()管理这些属性。 这些标识符是:

Standard Property IDs Property ID Description 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.

所有这些标准属性都是可选的。 XMLReader实现不需要支持它们。

从以下版本开始:
1.4