[jdom-interest] XmlOutputter - printNamespace - NO_NAMESPACE
outputs xmlns="", bug?
Eric VERGNAUD
eric.vergnaud at wanadoo.fr
Wed Jul 2 22:09:48 PDT 2003
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
More information about the jdom-interest
mailing list