[
Lists Home |
Date Index |
Thread Index
]
- From: "Box, Don" <dbox@develop.com>
- To: "'xml-dev@xml.org'" <xml-dev@xml.org>, "'David Megginson (E-mail)'" <david@megginson.com>
- Date: Sun, 12 Mar 2000 18:36:02 -0800
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
|