[jdom-interest] Namespace bug in SAXHandler?

ecky at free.fr ecky at free.fr
Tue Aug 21 04:26:29 PDT 2001


Hi again,

Something different this time: namespaces :-)

switched now from from beta6+(cvs 20.06.01) to the
beta7 available on the server and I encounter a
namespace error that I did not have before.

Parsing the file:
<?xml version="1.0" encoding="ISO-8859-1" ?> 
<candle:workingcontext xmlns:candle="http://www.candle.eu.org/">
  <candle:contextnode candle:active="1">
    <candle:label>Home</candle:label> 
... snip  

the attribute candle:active of the element candle:contextnode has
no namespace, i.e. local namespace prefix="" uri="", and I don't know
if this is correct.

I debuged compared the two versions in question and I found
the probable reason why:

In beta6+ the method of SAXHandler looks like:
342    public void startElement(String namespaceURI, String localName,
343                             String qName, Attributes atts)
344                             throws SAXException {
345        if (suppress) return;
346
347        Element element = null;
348
349        if ((namespaceURI != null) && (!namespaceURI.equals(""))) {
350            String prefix = "";
351
352            // Determine any prefix on the Element
353            if (localName != qName) {
354                int split = qName.indexOf(":");
355                prefix = qName.substring(0, split);
356            }
357            Namespace elementNamespace =
358                Namespace.getNamespace(prefix, namespaceURI);
359            element = factory.element(localName, elementNamespace);
360
361            // Remove this namespace from those in the temp declared list
362            if (declaredNamespaces.size() > 0) {
363                declaredNamespaces.remove(elementNamespace);
364            }
365
366            // It's now in available scope
367            availableNamespaces.addFirst(elementNamespace);
368        } else {
369            element = factory.element(localName);
370        }

and in beta7 it looks like this:
342    public void startElement(String namespaceURI, String localName,
343                             String qName, Attributes atts)
344                             throws SAXException {
345        if (suppress) return;
346
347        Element element = null;
348
349        if ((namespaceURI != null) && (!namespaceURI.equals(""))) {
350            String prefix = "";
351
352            // Determine any prefix on the Element
353            if (localName != qName) {
354                int split = qName.indexOf(":");
355                prefix = qName.substring(0, split);
356            }
357            Namespace elementNamespace =
358                Namespace.getNamespace(prefix, namespaceURI);
359            element = factory.element(localName, elementNamespace);
360
361            // Remove this namespace from those in the temp declared list
362            if (declaredNamespaces.size() > 0) {
363                declaredNamespaces.remove(elementNamespace);
364            }
365        } else {
366            element = factory.element(localName);
367        }

in beta7 the lines 365-367 are missing, and that's probably why
later in the same method (startElement) the namespace is not found
(method: private Namespace getNamespace(String prefix) returns local namespace)

My question is there a reason for that these lines are missing or
am I missing something?

cheers
ecky




More information about the jdom-interest mailing list