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 true indicates that the methods startElement() and endElement() provide namespace URIs and local names for elements and attributes. A value of false means prefixed element and attribute names are passed to startElement() and endElement(). 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 is true.

"http://xml.org/sax/features/namespace-prefixes"

When set to true, the attributes xmlns and xmlns: prefix are passed in the attribute list to startElement(). A value of false suppresses them. The parser also passes prefixed element and attribute names when set to true. The default is false unless "http://xml.org/sax/features/namespaces" is false, when the default becomes true. Set both "http://xml.org/sax/features/namespaces" and "http://xml.org/sax/features/namespace-prefixes" to true to ensure local names, namespace URIs and prefixed names are available.

"http://xml.org/sax/features/string-interning"

A value of true means all element names, prefixes, local names, attribute names and namespace URIs are interned with the method intern() of java.lang.String so they can be compared with ==.

"http://xml.org/sax/features/validation"

When set to true, the parser validates against its DTD. With false, it does not. Most default to false. When enabling validation, register an ErrorHandler with the XMLReader to receive validity errors.

"http://xml.org/sax/features/external-general-entities"

A value of true makes the parser resolve external parsed general entities itself. With false, it does not. Most supporting external entities default to true. Validating parsers always use true to check validity constraints.

"http://xml.org/sax/features/external-parameter-entities"

A value of true makes the parser resolve parameter entities itself. With false, it does not. Validating parsers always use true to 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 through startEntity() and endEntity() to the LexicalHandler. 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 after startDocument() 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 to DTDHandler and DeclHandler. With false they remain relative. Default: true. Relative URIs are never made absolute before reporting to LexicalHandler or EntityResolver.

"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 method error() to the registered ErrorHandler. Default: false, meaning no normalization check.

"http://xml.org/sax/features/use-attributes2"

When set to true, the object passed to startElement() as an Attributes object can be cast to an Attributes2 object, a subclass of Attributes with 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 in EntityResolver2 when an EntityResolver2 object is supplied to setEntityResolver().

"http://xml.org/sax/features/use-locator2"

When set to true, the object passed to setLocator() as a Locator object can be cast to a Locator2 object, 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 prefix xmlns to namespace URI "http://www.w3.org/2000/xmlns/". Default: false, leaving prefix xmlns unbound.

 

SAX core properties

SAX defines four optional core properties:

"http://xml.org/sax/properties/declaration-handler"

Its value is an org.xml.sax.ext.DeclHandler object receiving the document DTD’s ELEMENT, ATTLIST and parsed ENTITY declarations from the parser.

"http://xml.org/sax/properties/lexical-handler"

Its value is an org.xml.sax.ext.LexicalHandler object receiving comments and boundaries of CDATA sections and entities.

"http://xml.org/sax/properties/dom-node"

Its value is an org.w3c.dom.Node object representing the parser’s current node.

"http://xml.org/sax/properties/xml-string"

Its value is an java.lang.String object 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.String containing the document’s XML version, normally 1.0 or 1.1. This property is read-only.

 

  

 

 

 

back to top