[jdom-interest] Bug in DOMOutputter with the namespace declaration

Robinson, Andrew ARobinson at synchrony.net
Tue Sep 25 14:58:10 PDT 2001

DOMOutputter in B7 is behaving much differently than B5 and does not seem to
be treating name spaces correctly. The w3c Element generated has an
attribute with no namespace for the actual namespace declaration. This
shouldn't be an attribute in the Element, but rather namespace settings. See
below code:

Document doc;
Element elem;
org.w3c.dom.Element _3cElem;
org.w3c.dom.Node node;
Namespace syncNS = Namespace.getNamespace("sync", "urn:Synchrony");
DOMOutputter outputter = new DOMOutputter();
elem = new Element("username", syncNS).setText("testUname");
_3cElem = outputter.output(elem);
System.out.println("DOMOutputter: ");
org.w3c.dom.NamedNodeMap attrs = _3cElem.getAttributes();
for (int i = 0; i < attrs.getLength(); i++)
	node = attrs.item(i);
	System.out.println("Attr: " + node);
	System.out.println("URI: " + node.getNamespaceURI());
	System.out.println("Name: " + node.getNodeName());
	System.out.println("Value: " + node.getNodeValue());
	System.out.println("Prefix: " + node.getPrefix());

The output from this is:

Attr: xmlns:sync="urn:Synchrony"
URI: null
Name: xmlns:sync
Value: urn:Synchrony
Prefix: null

Correct me if I'm wrong but should the output not be:

URI: http://www.w3.org/2000/xmlns/
Name: sync
Value: urn:Synchrony
Prefix: xmlns

This is causing us a big problem with SOAP as it is adding the namespace to
the XML tag since it is not declared, and then adds the attribute, so in
essence, 2 name space declarations are added to the tag. Result from the
above code:

<sync:username xmlns:sync="urn:Synchrony"

As you can see, the xmlns is declared twice for 'sync' and therefore causing
parsing exceptions when the server gets the request. This code worked fine
in version B5, so a bug was introduced in either B6 or B7 of JDOM.

I'm currently changing our code to avoid using DOMOutputter since it seems
to be broken. I will use the DOM without JDOM for this code. As we'd prefer
to use JDOM, please advise if there is another solution. Until then, I'll
wait for a patch or B8 or 1.0 whichever comes next to go back to JDOM.

Andrew Robinson

More information about the jdom-interest mailing list