Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] Namespace inheritance after cloning

Alistair Young

2004-11-27

Replies:

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@(protected)
Isle of Skye
Scotland


_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.