[jdom-interest] possible bug with nested namespaces -resolved but not fixed

Brett McLaughlin brett at newinstance.com
Wed Aug 29 19:27:12 PDT 2001

> OK here is the problem but I am out of time and don't have an immediate
> solution.
>     public void endElement(String namespaceURI, String localName,
>                            String qName) throws SAXException {
>         if (suppress) return;
>         Element element = (Element)stack.pop();
>         if (stack.empty()) {
>             atRoot = true;
>         }
>         // Remove the namespaces that this element makes available
>         List addl = element.getAdditionalNamespaces();
>         if (addl.size() > 0) {
>             availableNamespaces.removeAll(addl);
>         }
>     }

One possible solution would be this:

Change availableNamespaces from a List to a Hashtable/HashMap. Make the key
the namespace (what's currently in the List), and the value a numeric value.
When adding a namespace to the list, see if it exists; if not, add it and a
value of "1". If it's there, increment it's value. Then it's easy to remove
a namespace. If it exists, decrement the value by 1; if the value is 0,
remove it (or just don't count it), if not leave it.

This covers walking the stack, additional declarations, and is a nicer
solution, IMHO. Anyone want to take a stab?

Brett McLaughlin
Enhydra Strategist   http://www.enhydra.org
Lutris Technologies http://www.lutris.com
O'Reilly Author       http://www.oreilly.com/catalog/javaxml2

More information about the jdom-interest mailing list