[jdom-interest] XmlOutputter - printNamespace - NO_NAMESPACE outputs xmlns="", bug?

Jason Hunter jhunter at servlets.com
Wed Jul 2 23:54:14 PDT 2003


Once you understand the default namespace is just "the namespace with an 
empty space prefix" things will be more clear to you.  The name "default 
namespace" is actually unfortunate in my opinion because it implies it's 
there in the absence of any other namespace, but in fact there's always 
a special "no namespace" in the absence of any other namespace.

The JDOM FAQ has more on this topic.

-jh-

Eric VERGNAUD wrote:
> le 3/07/03 3:52, Bradley S. Huffman à hip at csa.cs.okstate.edu a écrit :
> 
> 
>>John Jefferson writes:
>>
>>
>>>Why would there be no concept of a default namespace
>>>when building a document?
>>
>>There is, what your wanting to do is change several elements namespace after
>>the document has been build. And there is no automagical way to do that.
>>
> 
> 
> I still think there is a counter-intuitive behaviour with namespaces when
> creating a document. When you write:
> 
>     Element parent = new Element("parent",mynamespace);
>     elemlist = new ArrayList();
>     elem = new Element("child");
>     elem.setText("data");
>     elemlist.add(elem);
>     parent.setChildren(elemlist);
> 
> You get:
> 
>     <parent xmlns:'mynamespace'><child xmlns:''>data</child></parent>
> 
> While you would expect:
> 
>     <parent xmlns:'mynamespace'><child>data</child></parent>
> 
> The fact is you expect mynamespace to become the default namespace for all
> the tree below parent. But in order to get what you expect, you need to
> write:
> 
>     Element parent = new Element("parent",mynamespace);
>     elemlist = new ArrayList();
>     elem = new Element("child"",mynamespace); // specify ns for each child
>     elem.setText("data");
>     elemlist.add(elem);
>     parent.setChildren(elemlist);
> 
> Is this really the intended behaviour ? Someone said on this list there was
> a default namespace when creating documents too. How does this work ?
> 
> Regards,
> 
> Eric
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 




More information about the jdom-interest mailing list