Book HomeXML in a Nutshell

25.3. SAX Features and Properties

Absolute URIs are used to name a SAX parser's properties and features. Features have a boolean value; that is, for each parser, a recognized feature is either true or false. Properties have object values. SAX defines six core features and two core properties that parsers should recognize. In addition, parsers can add features and properties to this list, and most do.

SAX Core Features

All SAX parsers should recognize six core features. Of these six, two (http://xml.org/sax/features/namespaces and http://xml.org/sax/features/namespace-prefixes) must be implemented by all conformant processors. The other four are optional and may not be implemented by all parsers:

http://xml.org/sax/features/namespaces
When true, this feature indicates that the startElement( ) and endElement( ) methods provide namespace URIs and local names for elements and attributes. When false, the parser provides prefixed element and attribute names to the startElement( ) and endElement( ) methods. If a parser does not provide something it is not required to provide, then that value will be set to the empty string. However, most parsers provide all three (URI, local name, and prefixed name) regardless of the value of this feature. This feature is true by default.

http://xml.org/sax/features/namespace-prefixes
When true, this feature indicates that xmlns and xmlns:prefix attributes will be included in the attributes list passed to startElement( ). When false, these attributes are omitted. Furthermore, if this feature is true, then the parser will provide the prefixed names for elements and attributes. The default is false unless http://xml.org/sax/features/namespaces is false, in which case this feature defaults to true. You can set both http://xml.org/sax/features/namespaces and http://xml.org/sax/features/namespace-prefixes to true to guarantee that local names, namespace URIs, and prefixed names are all available.

http://xml.org/sax/features/string-interning
When this feature is true, all element names, prefixes, attribute names, namespace URIs, and local names are internalized using the intern( ) method of java.lang.String; that is, equal names compare equally when using ==.

http://xml.org/sax/features/validation
When true, the parser validates. When false, it doesn't. The default is false for most parsers. If you turn on this feature, you'll probably also want to register an ErrorHandler with the XMLReader to receive notice of any validity errors.

http://xml.org/sax/features/external-general-entities
When true, the parser resolves external parsed general entities. When false, it doesn't. The default is true for most parsers that can resolve external entities. Turning on validation automatically activates this feature because validation requires resolving external entities.

http://xml.org/sax/features/external-parameter-entities
When true, the parser resolves external parameter entities. When false, it doesn't. Turning on validation automatically activates this feature because validation requires resolving external entities.

SAX Core Properties

SAX defines two core properties, though implementations are not required to support them:

http://xml.org/sax/properties/dom-node
This property's value is an org.w3c.dom.Node object that represents the current node the parser is visiting.

http://xml.org/sax/properties/xml-string
This property's value is a java.lang.String object containing the characters that were the source for the current event. As of mid-2001, no Java parsers are known to implement this property.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.