This document is in the Public Domain.
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.
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
http://xml.org/sax/features/namespace-prefixes
http://xml.org/sax/features/string-interning
http://xml.org/sax/features/validation
http://xml.org/sax/features/external-general-entities
http://xml.org/sax/features/external-parameter-entities
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
org.w3c.dom.Node
http://xml.org/sax/properties/xml-string
java.lang.String