[jdom-interest] Bug in DOMOutputter with the namespace declar ation

Robinson, Andrew ARobinson at synchrony.net
Wed Sep 26 07:13:33 PDT 2001


Here is the full code. SOAP adds a name space declaration if one is not
present. Due to the fact that the Node is not constructed correctly
(attributes), SOAP does not recognize it as a name space declaration, and
creates one. This causes two definitions to be present in one tag.

Attached is the full code

-Andrew

-----Original Message-----
From: philip.nelson at omniresources.com
[mailto:philip.nelson at omniresources.com]
Sent: Tuesday, September 25, 2001 9:27 PM
To: ARobinson at synchrony.net; jdom-interest at jdom.org
Subject: RE: [jdom-interest] Bug in DOMOutputter with the namespace
declar ation


I ran your code and got this:

<?xml version="1.0" encoding="UTF-8"?>
<sync:username xmlns:sync="urn:Synchrony">testUname</sync:username>

Try the cvs version and let us know.

> 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();
> System.out.println("Attrs:");
> 			
> 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:
> 
> DOMOutputter:
> Attrs:
> 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"
> xmlns:sync="urn:Synchrony">testUname</sync:username>
> 
> 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.
> 
> Thanks,
> Andrew Robinson
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestBug.java
Type: application/octet-stream
Size: 3164 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010926/a9bdb4b6/TestBug.obj


More information about the jdom-interest mailing list