While adding a new node into SOAPElement I'm getting an extra, unwanted attribute xmlns="". How can I solve it?
...
SOAPFactory factory = SOAPFactory.newInstance();
SOAPElement securityElem = factory.createElement("Security", null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement tokenElem = factory.createElement("UsernameToken");
...
securityElem.addChildElement(tokenElem);
Result:
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken xmlns=""/> </Security>
But I need this:
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken/> </Security>
If you want the element to be in the same namespace as its parent element, you must explicitly create it in that namespace by supplying the URI to the createElement() call. If you create a no-namespace element (as you have done), then the serializer inserts a namespace undeclaration xmlns=""
to indicate that that the element is not in the same namespace as its parent.