[jdom-interest] Namespace inheritance after cloning

Alistair Young alistair at smo.uhi.ac.uk
Sat Nov 27 17:28:43 PST 2004


I have a strange problem. I've read the archives and the FAQ and
understand the non inheritance of prefix:local style namespaces. However,
when I do:

Document root =
<root xmlns="http://test.ns">
</root>

Document next =
<next>some text</next>

root.getRootElement().addContent((Content)next.getRootElement().clone());

I get:
<root xmlns="http://test.ns">
  <next xmlns="">some text</next>
</root>

and it breaks the XML schema validation! <next> should obviously be in the
test.ns namespace. JDOM seems to want to put it in an empty namespace.

Now, the weird thing is, if I create <next> with the same namespace as
<root>, JDOM still replaces it with xmlns="".

If <root> doesn't have a namespace, then the xmlns="" isn't added to <next>.
Nowhere in the code is xmlns="" generated when creating the <next> Element.

Is there any way to stop this happening? It seems unintuitive to the
namespace aware mind ;)

thanks,
Alistair


-- 
Alistair Young
Senior Software Engineer
UHI at Sabhal Mòr Ostaig
Isle of Skye
Scotland




More information about the jdom-interest mailing list