[jdom-interest] bug in Element.getCopy ?

Jochen Strunk strunk at signal7.de
Fri Mar 2 07:55:09 PST 2001

>By your definition above, a default namespace is required for it to apply to
>child elements with matching prefixes or no prefixes so...
><element xmlns="http://foo">
>         <child1 />
>         <child2 />
>would fit your scenario but in the defaul case with the NO_NAMESPACE
>         <child1 />
>         <child2 />
>has no default namespace so changing the namespace of <element> would not
>imply a change to the children, correct?
>What I would like is concrete examples so I can write tests to confirm what
>is supposed to be happening.

Hi Philip,

try the following example:

Element element = new Element("element", Namespace.getNamespace("http://foo"));
Element child1 = new Element("child1");
Element child2 = new Element("child2");


XMLOutputter op = new XMLOutputter("     ", true);
op.output(element, System.err);

It outputs:
<element xmlns="http://foo">
      <child1 xmlns="" />
      <child2 xmlns="" />

In my opinion this is incorrect, the correct output would be:
<element xmlns="http://foo">
      <child1 />
      <child2 />

child1 and child2 should be created in no namespace, as stated by the jdom 
api docs: "This will create an Element in no Namespace.". In that case, the 
default namespace applied to element (which is "http://foo") would 
automatically be applied to child1 and child2.
But child1 and child2 are created with a default namespace that is set to 
the empty string which is something completely different because it 
eliminates the default namespace of the parent and leads to the false output.

The namespace spec says:
The default namespace can be set to the empty string. This has the same 
effect, within the scope of the declaration, of there being no default 

My suspicion is you are using "the default namespace set to the empty 
string" where you should be using "no namespace".

hope this helps,

(-) Jochen Strunk
(-) SIGNAL 7 Gesellschaft für Informationstechnologie mbH
(-) Brüder-Knauß-Str. 79 - 64285 Darmstadt,
(-) Tel: 06151 665402, Fax: 06151 665373
(-) strunk at signal7.de, www.signal7.de

More information about the jdom-interest mailing list