[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

SAX2: a new namespace proposal

  • From: "Don Park" <donpark@d...>
  • To: <xml-dev@i...>
  • Date: Mon, 20 Dec 1999 13:52:46 -0800

extends documenthandler
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@d...
Docuverse   -   http://www.docuverse.com


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



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.