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

Yet another SAX2 observation

  • From: "Box, Don" <dbox@d...>
  • To: "'xml-dev@x...'" <xml-dev@x...>, "'David Megginson (E-mail)'" <david@m...>
  • Date: Sun, 12 Mar 2000 18:36:02 -0800

implements defaulthandler
Title: Yet another SAX2 observation

In trying to properly implement the in-scope namespaces Infoset property, I found the following inconvenience with SAX2. The ordering of startPrefixMapping and startElement requires the implementation of ContentHandler to either (a) create a new "scoping context" for each namespace declaration or (b) keep a data member around to note that a new element has started. The current docs regarding calling NamespaceSupport.pushContext at every startElement notification doesn't work. Assume the following implementation of ContentHandler:

class me implements DefaultHandler {
  void startPrefixMapping(String p, String u) {
    ns.declarePrefix(p, u);
  }
  void startElement(...) {
    ns.pushContext();
  }
  void endElement(...) {
    ns.popContext();
  }
}

This implementation chokes, since the pushing needs to happen at the first startPrefixMapping, not at the startElement notification. Rather, to implement this correctly, one must write the code as follows:

class me implements DefaultHandler {
  void startPrefixMapping(String p, String u) {
    ns.pushContext();
    ns.declarePrefix(p, u);
  }
  void startElement(...) {
  // do nothing wrt context mgmt.
  }
  void endElement(...) {
  // do nothing wrt context mgmt.
  }
  void endPrefixMapping(String p) {
    ns.popContext();
  }
}

I have a feeling this isn't what people had in mind. I actually think the flaw is in ContentHandler, since the current design requires the implementation to retain additional state in order to match up namespace declarations with the elements they correspond to.

DB
http://www.develop.com/dbox


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.