SAX2: Features and Properties

SAX2 adds standard methods to query and set features and properties in an XMLReader. It is now possible to request an XML reader to validate (or not to validate) a document, or to internalize (or not to internalize) all names, using the getFeature, setFeature, getProperty, and setProperty methods:

try {
  if (xmlReader.getFeature("http://xml.org/sax/features/validation")) {
    System.out.println("Parser is validating.");
  } else {
    System.out.println("Parser is not validating.");
  }
} catch (SAXException e) {
  System.out.println("Parser may or may not be validating.");
}

There is no fixed set of features or properties available for SAX2: implementors are free to define new features and properties as needed. All feature and property names are fully-qualified URIs (often URLs), such as "http://www.acme.com/features/foo"; as with Namespace URIs, people should always define feature and property names based on URIs that they control.

If an application attempts to query or set a feature that the XML reader does not recognize, the XML reader throws a SAXNotRecognizedException; if the application attempts to set a feature state or property value that the XML reader cannot support at that time, or attempts to modify a feature or property when it is read-only, the XML reader throws a SAXNotSupportedException.

One important application for properties is getting and setting extension event handlers, for event types not supported by the four core SAX2 handlers, EntityResolver, DTDHandler, ContentHandler, and ErrorHandler. Outside parties are free to define handlers for any kinds of events, and to create properties for setting and querying them.

All XML readers are required to recognize the "http://xml.org/sax/features/namespaces" and the "http://xml.org/sax/features/namespace-prefixes" features (see below), and to support a true value for the namespaces property and a false value for the namespace-prefixes property: these requirements ensure that all SAX2 XML readers can provide the minimal required Namespace support for higher-level specs such as RDF, XSL, XML Schemas, and XLink. XML readers are not required to recognize or support any other features or any properties, even the core ones listed below.

Core Features

While anyone is free to define new SAX2 features, there is a core reference set of features that are application to a wide range of applications, and that many SAX2 XML readers may choose to support. Note that features may be read-only or read/write, and that they may be modifiable only when parsing, or only when not parsing.

http://xml.org/sax/features/namespaces
true: Perform Namespace processing.
false: Optionally do not perform Namespace processing (implies namespace-prefixes). See SAX2: Namespaces for further information.
access: (parsing) read-only; (not parsing) read/write
http://xml.org/sax/features/namespace-prefixes
true: Report the original prefixed names and attributes used for Namespace declarations.
false: Do not report attributes used for Namespace declarations, and optionally do not report original prefixed names.
access: (parsing) read-only; (not parsing) read/write
http://xml.org/sax/features/string-interning
true: All element names, prefixes, attribute names, Namespace URIs, and local names are internalized using java.lang.String.intern.
false: Names are not necessarily internalized.
access: (parsing) read-only; (not parsing) read/write
http://xml.org/sax/features/validation
true: Report all validation errors (implies external-general-entities and external-parameter-entities).
false: Do not report validation errors.
access: (parsing) read-only; (not parsing) read/write
http://xml.org/sax/features/external-general-entities
true: Include all external general (text) entities.
false: Do not include external general entities.
access: (parsing) read-only; (not parsing) read/write
http://xml.org/sax/features/external-parameter-entities
true: Include all external parameter entities, including the external DTD subset.
false: Do not include any external parameter entities, even the external DTD subset.
access: (parsing) read-only; (not parsing) read/write

Core Properties

While anyone is free to define new SAX2 properties, there is a core reference set of properties that are application to a wide range of applications, and that many SAX2 XML readers may choose to support. Note that properties may be read-only or read/write, and that they may be modifiable only when parsing, or only when not parsing.

http://xml.org/sax/properties/dom-node
data type: org.w3c.dom.Node
description: When parsing, the current DOM node being visited if this is a DOM iterator; when not parsing, the root DOM node for iteration.
access: (parsing) read-only; (not parsing) read/write
http://xml.org/sax/properties/xml-string
data type: java.lang.String
description: The literal string of characters that was the source for the current event.
access: read-only

$Id$