SAX2 Namespace Support

David Megginson david at megginson.com
Mon Dec 20 23:03:45 GMT 1999


OK, here goes...

Background
----------

I accept Tim Bray's argument that Namespace-qualified names should be
passed on in two parts and not one, and that Namespace-aware
processing is the future of XML.

I accept James Clark's argument that there must be a mechanism for
passing on the original prefix if the parser supports doing so and the 
application desires it, if only for DOM2 support.


General Rules
-------------

1. By default, SAX2 parsers shall perform Namespace processing unless
   explicitly requested not to do so.  There's no point having them
   start in an indeterminate state, or in allowing SAX2 parsers not to
   do Namespace processing.  I will provide a filter that can be
   embedded in the driver for parsers that don't do NS processing
   natively.

2. There will be features for (i) requesting that the original prefix
   be prepended to each local name and (ii) turning off Namespace
   processing altogether.  The default value for each of these
   features will be false, and no parser is required to support either 
   of them.

3. If a LexicalHandler is set, the parser may use it to report the
   scope of Namespace declarations.  Note that this is a little
   brittle, and probably less useful than people think, but that it is
   essential for XSLT.  Not all parsers will support LexicalHandler.

4. Namespace-qualified names are always reported as two separate
   strings: the Namespace URI and the local name.  The local name may
   have the original prefix prepended at client request, but the
   prefix will not be there by default.

The idea of all of this is that fully-cooked Namespace processing is
the default behaviour and the normal, transparent operating mode for
SAX2 -- most application writers need never know that other modes are
available.

However, there are optional, non-obtrusive mechanisms for passing on
extra information (such as the original prefixes and the scope of NS
declarations).  The presence or absence of support for these optional
features can be determined by feature queries.


Implementation
--------------

This implementation is based largely on suggestions from James Clark.


[from org.xml.sax2.DocumentHandler]

  public void startElement (String ns, String name, 
                            AttributeList atts)
    throws SAXException;

  public void endElement (String ns, String name)
    throws SAXException;


[org.xml.sax2.AttributeList]

  public class AttributeList
  {
    public int getLength ();

    public String getNamespaceURI (int i);
    public String getName (int i);
    public String getType (int i);
    public String getValue (int i);

    public String getType (String ns, String localName);
    public String getValue (String ns, String localName);

                    // For searching on prefixed names
    public String getType (String name);
    public String getValue (String name);
  }


[from org.xml.sax2.LexicalHandler]

  public void startNamespaceDeclScope (String prefix, String uri)
    throws SAXException;

  public void endNamespaceDeclScope (String prefix)
    throws SAXException;


Unless someone shows a catastrophic problem with all this (not a
purely aesthetic one), I plan to go ahead to other SAX2 problems now.


All the best,


David

-- 
David Megginson                 david at megginson.com
           http://www.megginson.com/

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)





More information about the Xml-dev mailing list