XML technologies / XML / XML in a Nutshell / SAX reference / Features and properties of SAX
(Excerpt from “XML in a Nutshell” by Elliotte Rusty Harold & W. Scott Means)
SAX features and properties are named by absolute URIs. Features have Boolean values, either true or false. Properties have object values. SAX 2.0 defines six features and two properties parsers must recognize but need not implement. SAX 2.0.2 adds nine more. Most parsers also define their own.
SAX core features
Every SAX parser should recognize these six. The two features "http://xml.org/sax/features/namespaces" and "http://xml.org/sax/features/namespace-prefixes" must be implemented for SAX2 conformance. The other four are optional.
- "http://xml.org/sax/features/namespaces"
Setting this to
trueindicates that the methodsstartElement()andendElement()provide namespace URIs and local names for elements and attributes. A value offalsemeans prefixed element and attribute names are passed tostartElement()andendElement(). Information not required and not supplied is represented by an empty string. Most parsers support all three values regardless of this feature: URI, local name and prefixed name. The default istrue.- "http://xml.org/sax/features/namespace-prefixes"
When set to
true, the attributesxmlnsandxmlns:prefixare passed in the attribute list tostartElement(). A value offalsesuppresses them. The parser also passes prefixed element and attribute names when set totrue. The default isfalseunless "http://xml.org/sax/features/namespaces" isfalse, when the default becomestrue. Set both "http://xml.org/sax/features/namespaces" and "http://xml.org/sax/features/namespace-prefixes" totrueto ensure local names, namespace URIs and prefixed names are available.- "http://xml.org/sax/features/string-interning"
A value of
truemeans all element names, prefixes, local names, attribute names and namespace URIs are interned with the methodintern()ofjava.lang.Stringso they can be compared with ==.- "http://xml.org/sax/features/validation"
When set to
true, the parser validates against its DTD. Withfalse, it does not. Most default tofalse. When enabling validation, register anErrorHandlerwith theXMLReaderto receive validity errors.- "http://xml.org/sax/features/external-general-entities"
A value of
truemakes the parser resolve external parsed general entities itself. Withfalse, it does not. Most supporting external entities default totrue. Validating parsers always usetrueto check validity constraints.- "http://xml.org/sax/features/external-parameter-entities"
A value of
truemakes the parser resolve parameter entities itself. Withfalse, it does not. Validating parsers always usetrueto check validity constraints.
SAX 2.0.2 adds eight more standard features, as optional as those in SAX 2.0:
- "http://xml.org/sax/features/lexical-handler/parameter-entities"
When set to
true, the parser reports parameter-entity boundaries throughstartEntity()andendEntity()to theLexicalHandler. Defaults are implementation-specific.- "http://xml.org/sax/features/is-standalone"
Indicates whether, in the XML declaration,
standalone="yes"is declared. Read-only; available only afterstartDocument()completes and before document reading ends.- "http://xml.org/sax/features/resolve-dtd-uris"
When set to
true, relative URIs in notation, unparsed-entity and external-entity declarations become absolute before reporting toDTDHandlerandDeclHandler. Withfalsethey remain relative. Default:true. Relative URIs are never made absolute before reporting toLexicalHandlerorEntityResolver.- "http://xml.org/sax/features/unicode-normalization-checking"
When set to
true, text is checked against the Unicode Normalization Form C standard recommended by XML 1.1. Normalization problems are reported through the nonfatal methoderror()to the registeredErrorHandler. Default:false, meaning no normalization check.- "http://xml.org/sax/features/use-attributes2"
When set to
true, the object passed tostartElement()as anAttributesobject can be cast to anAttributes2object, a subclass ofAttributeswith methods reporting whether an attribute was declared in the DTD, specified in the instance, or both.- "http://xml.org/sax/features/use-entityresolver2"
When set to
true, the parser uses extra methods defined inEntityResolver2when anEntityResolver2object is supplied tosetEntityResolver().- "http://xml.org/sax/features/use-locator2"
When set to
true, the object passed tosetLocator()as aLocatorobject can be cast to aLocator2object, adding methods to identify an entity or document’s encoding and XML version.- "http://xml.org/sax/features/xmlns-uris"
When set to
true, the parser follows a backward-compatible namespace specification binding the prefixxmlnsto namespace URI "http://www.w3.org/2000/xmlns/". Default:false, leaving prefixxmlnsunbound.
SAX core properties
SAX defines four optional core properties:
- "http://xml.org/sax/properties/declaration-handler"
Its value is an
org.xml.sax.ext.DeclHandlerobject receiving the document DTD’sELEMENT,ATTLISTand parsedENTITYdeclarations from the parser.- "http://xml.org/sax/properties/lexical-handler"
Its value is an
org.xml.sax.ext.LexicalHandlerobject receiving comments and boundaries ofCDATAsections and entities.- "http://xml.org/sax/properties/dom-node"
Its value is an
org.w3c.dom.Nodeobject representing the parser’s current node.- "http://xml.org/sax/properties/xml-string"
Its value is an
java.lang.Stringobject containing the current document’s source characters. No parser implemented it as of mid-2004.
SAX 2.0.2 adds one standard property:
- "http://xml.org/sax/properties/document-xml-version"
Its value is an object of type
java.lang.Stringcontaining the document’s XML version, normally 1.0 or 1.1. This property is read-only.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML in a Nutshell” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de