[XML-SIG] SAX 2.0: Namespaces
Lars Marius Garshol
larsga@garshol.priv.no
15 May 2000 21:46:40 +0200
Namespace handling in SAX 2.0
-----------------------------
--- Processing modes:
- Namespace processing. In this mode full namespace processing is
on, and namespace declaration attributes are hidden. This is
the default mode, and support for it is required.
http://xml.org/sax/features/namespaces on
http://xml.org/sax/features/namespace-prefixes off
- Namespace processing with prefixes available. In this mode
namespace processing is on, and namespace declaration attributes
are not hidden. Support for this mode is not required.
http://xml.org/sax/features/namespaces on
http://xml.org/sax/features/namespace-prefixes on
- XML 1.0 processing. In this mode there is no namespace processing.
Support for this mode is not required.
http://xml.org/sax/features/namespaces off
http://xml.org/sax/features/namespace-prefixes on
--- Name representation
(What is set out here goes for both ContentHandler and Attributes.)
- All element and attribute names consist of a namespace name
(represented as a (uri, localname) tuple) and a qualified name
(the raw name, represented by a string). Which parts of this
information is available depends on the processing mode and the
parser, but the API provides for all this information.
- During namespace processing, what namespace declarations are in
effect at any point in the document can be found from the
startPrefixMapping/endPrefixMapping events on the ContentHandler
interface.
- The namespace name:
- Required during namespace processing, optional otherwise.
- If the name is not connected to a namespace, the name tuple
takes the form (None, localname).
- Namespace processing is off and the parser is not providing
namespace names this this value should be the same as the
qualified name. (Alternatively, it could be None. My mind is not
made up on this.)
- The qualified name:
- Required when namespace-prefixes is on, optional otherwise. That
is, optional during pure namespace processing mode, required
with XML 1.0 processing mode and namespace processing with
prefixes.
- If the parser does not make qualified names available, the value
is None. If it does make them available, the value is a string.
--- An example
<h:hello xmlns:h="http://www.greeting.com/ns/" id="a1"
h:person="David"/>
- In namespace processing (without prefixes) mode, the following
will
be reported:
- an element
- name: ("http://www.greeting.com/ns/", "hello")
- qname: "h:hello" or None
- an attribute
- name: (None, "id")
- qname: "id" or None
- an attribute
- name: ("http://www.greeting.com/ns/", "person")
- qname: "h:person" or None
- In namespace processing with prefixes mode, the following will be
reported:
- an element
- name: ("http://www.greeting.com/ns/", "hello")
- qname: "h:hello"
- an attribute
- name: (None, "id")
- qname: "id"
- an attribute
- name: ("http://www.greeting.com/ns/", "person")
- qname: "h:person"
- an attribute
- name: (None, None) # the attribute cannot be looked up by
this name...
- qname: "xmlns:h"
- In XML 1.0 processing mode, the following will be reported:
- an element
- name: ("http://www.greeting.com/ns/", "hello") or None
- qname: "h:hello"
- an attribute
- name: (None, "id") or None
- qname: "id"
- an attribute
- name: ("http://www.greeting.com/ns/", "person") or None
- qname: "h:person"
- an attribute
- name: (None, None) or None
- qname: "xmlns:h"