SAAJ 1.3: SoapBody.addDocument throws NAMESPACE_ERR

Hello,

I'm trying to add a Document to a SoapBody via the addDocument method.

The node I'm adding looks like this:

<ns1:DSDOrderRequest xmlns="mooncompany"

xmlns:ns1="http://hnsp.inf-bb.uni-jena.de/SWS-Challenge"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

...

My Problem is, I get a namespace error:

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

The reason is, my node is added using the name "ns1:DSDOrderRequest" but no namespace URI is specified.

I debugged this using SourceCode and jar file from https://saaj.dev.java.net/ (Version 1.3) and found the following lines of code:

com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl

boolean domLevel20 = source.getOwnerDocument().getImplementation().hasFeature("XML", "2.0");

// Create element according to namespace support/qualification.

if(domLevel20 == false || source.getLocalName() == null)

newElement = createElement(source.getNodeName());

else

newElement = createElementNS(source.getNamespaceURI(),

source.getNodeName());

and the first line is executed which explains why the node is added using the name "ns1:DSDOrderRequest" instead of the name "DSDOrderRequest" with the correct prefix and namespace URI.

What I don't know is how to deal with this.

Any help would be greatly appreciated. Took me a lot of time to investigate this issue already :-(

Thanks in advance,

Uli

[1600 byte] By [Torana] at [2007-10-2 20:28:29]
# 1

Hello,

I found the issue. Pretty stupid mistake:

I had been parsing my document using JAXP and the line that was missing was the second one:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(true);

My parser was simply not namespace-aware... :-(

best regards,

Uli

PS.: Would be nice if SAAJ was not that vulnerable against this or threw a more helpfull error messsage though...

ukuestera at 2007-7-13 23:11:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...