Reputation: 209
I have to get a SOAP part like this one:
<PutMake xmlns="urn:PutMake">
<x1/>
<x2/>
....
</PutMake>
So I use this code to do it:
SOAPElement putMakeElement = soapBody.addChildElement(new QName("PutMake"));
putMakeElement.addNamespaceDeclaration("", "urn:PutMake");
// then adding child elements...
But the problem is I get the out SOAP like this:
<PutMake xmlns="">
<x1 xmlns="urn:PutMake"/>
<x2 xmlns="urn:PutMake"/>
....
</PutMake>
The "xmlns" parameter for PutMake I need is empty, but the parameter of the child elements have it set correctly, while they are supposed to not have that attribute at all.
I also tried using addAttribute instead of addNamespaceDeclaration, but the output is the same.
Why can it be like this?..
Upvotes: 1
Views: 563
Reputation: 122414
The problem is that new QName("PutMake")
gives you a QName whose namespace URI is empty. You need to use new QName("urn:PutMake", "PutMake", "")
to get a QName with the namespace URI you require.
Upvotes: 1