[jdom-interest] Attribute namespaces - RESOLVED?

Kevin Stadlmayer kstadlmayer at mpowertech.com
Thu Oct 5 14:58:59 PDT 2000

I believe I have isolated the issue and fixed it.

DOMBuilder.java buildTree() iterates through all elements and processes them
and their attributes.  All attributes with "xmlns:" are used to create and
store Namespace objects in a Hashmap.  All others are added to a List of
regular attributes.

When this new List is processed, it is not checked whether there is a
namespace for each attribute.  Instead of checking and creating an Attribute
object with that Namespace uri, a namespace-less attribute is added to the
element (element.addAttribute(<name>, <value>)).  This is where the ":" is
causing an IllegalNameException to be thrown.

I added a check for this situation, and my org.w3c.Document generated by
Xerces gets processed no problem into the org.jdom.Document, and back again
with the namespaces seemingly preserved.  The check is as follows.
Starting on line 359 of DOMBuilder.java:

  // don't send xmlns attributes to JDOM
  if (!attName.startsWith("xmlns:")) {
      Attribute attribute = null;

      // check if this attribute has a namespace specified
      split = 0;
      if ((split = attName.indexOf(":")) != -1) {
         String prefix = attName.substring(0, split);
         String localName = attName.substring(split + 1);
         String uri =
         attribute =
            new Attribute(localName, prefix, uri, att.getNodeValue());
      else {
         // no namespace
         attribute = new Attribute(att.getNodeName(),


I will continue to test this over the next few days, and I'll let you know
if I have any problems.

Another thing I noticed is the seeming lack of support for default
namespaces.  Correct me if I'm wrong, but if there is no namespace prefix
attached to the element name, the element is just assumed to have no
namespace (lines 336-342).  I believe that all that needs to be done is keep
track of the current default namespace, and instead of creating each element
with no namespace, use the default.  This shouldn't be too hard.  I'll look
into it, and keep you posted.

I'll send the fix to Jason Hunter.

More information about the jdom-interest mailing list