SAX2: a new namespace proposal

Don Park donpark at docuverse.com
Mon Dec 20 21:51:38 GMT 1999


Here is a proposal that has very little impact on SAX
interfaces:

  // NamespaceHandler is a callback interface for
  // handling namespace declarations
public interface NamespaceHandler {
  void startNamespace(String uri, String prefix);
  void endNamespace(String uri, String prefix);
}

  // New interface that provides namespace support
  // to DocumentHandlers similarly to the way Locator
  // provides source information.
  // NOTE: With the exception of getNameObject,
  // Namespaces methods must be invoked within
  // startElement method.
public interface Namespaces
{
  Object getNameObject(String uri,
           String localPart);
    // get a unique non-mutable opaque object
    // representing a fully qualified name

  boolean equals(String rawName, Object no);
    // see if given name string and name object
    // are equivalent.
  boolean equalsNS(String rawName, Object no);
    // see if given name string belongs to the
    // namespace of given name object.

    // same as above except uses components
    // of a name object.
  boolean equals(String rawName,
            String uri, String localName);
  boolean equalsNS(String rawName,
            String uri);

    // name information methods
  String getNameURI(String rawName);
  String getNamePrefix(String rawName);
  String getNameLocalPart(String rawName);
}

  // DocumentHandlerNS extends DocumentHandler
  // with namespace support
public interface DocumentHandlerNS extends
  DocumentHandler
{
  void setDocumentNamespaces(Namespaces nss);
}

  // ParserNS extends Parser with namespace
  // support
public interface ParserNS extends Parser
{
  void setNamespaceHandler(NamespaceHandler h);
}

With above changes, SAX implementations can
detect whether an XML application is namespace-
aware or not by checking whether DocumentHandlerNS
is being used or not.

Here is an example of a DocumentHandler based on
this proposal:

public class MySAXApp implements DocumentHandlerNS {
  Namespaces _nss;
  Object     _foo, _bar;
  void setDocumentNamespaces(Namespaces nss) {
    _nss = nss;
    _foo = nss.getNameObject(MY_NS_URI, "foo");
    _bar = nss.getNameObject(MY_NS_URI, "bar");
  }
  void startElement(String name, AttributeList atts) {
    if (_nss.equals(name, _foo)) {
      // its our 'foo'
      String prefix = _nss.getNamePrefix(name);
        // what prefix was used if any.  If default NS
        // is in effect, this returns null.
    }
    else if (_nss.equalsNS(name, MY_NS_URI)) {
      // its not foo but one of ours
    }
  }
}

There might be some holes in this proposals so please
constrain your comments to the design approach rather
than design specifics.  Key point is the use of Locator
like mechanism.

Best,

Don Park    -   mailto:donpark at docuverse.com
Docuverse   -   http://www.docuverse.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