SAX2 is fully namespace aware:
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts)
throws SAXException
public void endElement(String namespaceURI, String localName, String qualifiedName)
throws SAXException
public void startPrefixMapping(String prefix, String uri)
throws SAXException
public void endPrefixMapping(String prefix)
throws SAXException
Namespace handling is controlled by these two properties:
http://xml.org/sax/features/namespaces
http://xml.org/sax/features/namespace-prefixes
http://xml.org/sax/features/namespaces feature determines
whether namespace URIs and local names are passed to
startElement()
and endElement()
.
The default, true, passes both namespace URIs and local names.
However, if http://xml.org/sax/features/namespaces is false,
then the parser may pass the namespace URI and the local name,
or it may just pass empty strings for these two arguments.
http://xml.org/sax/features/namespace-prefixes feature determines two things:
Whether or not namespace declaration xmlns
and
xmlns:prefix
attributes are included in the Attributes
object passed to startElement()
.
The default, false, is not to include them.
Whether or not the qualified names should be passed as the
third argument to the startElement()
method.
The default, false, is, not to require qualified names.
However, even if http://xml.org/sax/features/namespace-prefixes is false,
parsers are allowed to report the qualified name, and most do so.
In other words,
The parser is only guaranteed to provide the namespace URIs and local names of elements and attributes if http://xml.org/sax/features/namespaces is true (which it is by default).
The parser is only guaranteed to provide the qualified names of elements and attributes if http://xml.org/sax/features/namespace-prefixes is true (which it is not by default).
The parser provides namespace declaration attributes if and only if http://xml.org/sax/features/namespace-prefixes is true (which it is not by default).
The parser always has the option to provide the namespace URI, local name, and qualified name, regardless of the values of http://xml.org/sax/features/namespaces and http://xml.org/sax/features/namespace-prefixes. However, you should not rely on this behavior.
Bottom line: the defaults are fine as long as you don’t care about namespace prefixes, only local names and URIs.