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

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Jul 29 08:31:41 PDT 2003


Elliotte Rusty Harold wrote:
> At 2:36 AM +0200 7/5/03, Eric VERGNAUD wrote:
> 
>> Would someone on this list be less happy if dummies are more happy ?
> 
> Yes. What you're asking makes the API more complex. It makes it harder 
> to explain. It makes it less consistent. It is unneeded by almost 
> everyone who uses JDOM. It is a completely different model of namespaces 
> than what JDOM uses now. Adding an option here would make JDOM's 
> internals more complicated, less robust, and more buggy. It helps users 
> do the wrong thing, and encourages them to misunderstand and misuse 
> namespaces. It's a lose-lose situation. It's a very bad idea, and it 
> isn't going to happen.

I do agree with Elliotte for both complexity and consistency. The change 
you're proposing will make Element to behave inconsistently when attached to 
different documents (with our without the flag) or different parents (with or 
without a default namespace, with different default namespaces).

This change would also mean that the result of outputting a document through 
XMLOuputter will not be consistent with the JDOM in-memory representation of 
this document.
This is a major issue because if would mean that the code that was used to 
create/modify a JDOM document (using NO_NAMESPACE to navigate) will not be 
able to modify it after parsing (actual namespaces would be required).

Additionally, even the "people at Sun [that] are getting aware that Java still 
needs to be improved" do force you to cope with namespaces when dealing with 
XML. You should have a look at javax.xml.soap.SOAPElement and 
javax.xml.soap.Name in JAXM and the javax.xml.namespace package in JAX-RPC.

Finally, once one made the effort of understanding what are XML namespaces and 
how they work, I don't think the following code is so verbose it would require 
namespace boxing/unboxing !
             Namespace ns = Namespace.getNamespace("http://.../");

             Element root = new Element("root", ns);
             Document doc = new Document(root);

             root.addContent(new Element("a", ns));
             root.addContent(new Element("b", ns));
             root.addContent(new Element("c", ns));
             root.addContent(new Element("d", ns));
             root.addContent(new Element("e", ns));
             ...
The complexity of building XML documents with JDOM does not lie in adding the 
4 character sequence ", ns" to all elements created.

Laurent




More information about the jdom-interest mailing list