[jdom-interest] Namespace Collision exception when adding an additional namespace

Bradley S. Huffman hip at a.cs.okstate.edu
Mon May 16 09:19:48 PDT 2005

"PJ Fanning" writes:

> I got an exception when I executed code along the lines of the following:
> 	Namespace ns1 = Namespace.getNamespace("aaa", "http://acme.com/aaa");
> 	Element e = new Element("aaa", ns1);
> 	e.setAttribute("att1", "att1");
> 	Namespace defns = Namespace.getNamespace("http://acme.com/default");
> 	e.addNamespaceDeclaration(defns);
> I want to declare an element that is in the 'aaa' namespace but that also dec
> lares a default namespace that is inherited by other elements. However, I get
>  this exception:

Child elements don't inherit namespaces from their parents in JDOM.
You have to explicitly place them in the desired namespace (as in 
new Element("bbb", defns)).

> org.jdom.IllegalAddException: The namespace xmlns="http://acme.com/default" c
> ould not be added as a namespace to "aaa:aaa": The namespace prefix "" collid
> es with an attribute namespace prefix on the element
> I think that the code in the Verifier is incorrect. It seems to assume that a
> ttributes that have no explicit namespace are in the default namespace. This 
> is not my understanding of the XML spec.
> The code above works if I add the attribute after the additional namespace de
> claration.

Yep, it looks like a bug.


More information about the jdom-interest mailing list