I am calling third party soap where each element must have a namespace. I am calling from Java to a .NET service. In some elements, I must include "http:/abc.com". Other times, I must include xmlns:"". For example;
<GetYears xmlns="http://example.com">
<oCar xmlns="">
<make xmlns="http://example.com">Ford</make>
<model xmlns="http://example.com">F250</make>
</oCar>
</GetYears>
I am using javax.xml.soap.*
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
...
QName bodyName = new QName("http://example.com", "GetAircraftDueListItems");
SOAPElement soapBodyElement = soapBody.addBodyElement(bodyName);
QName qName = new QName("", "oCar");
SOAPElement carEement = soapBodyElement.addChildElement(qName);
By default, this produces the following output which is rejected by the service because the namespace "" is missing on oCar.
<GetYears xmlns="http://example.com">
<oCar>
<make xmlns="http://example.com">Ford</make>
<model xmlns="http://example.com">F250</make>
</oCar>
</GetYears>
It appears that an empty namespace is ignored. Is there a way to force the element to include xmlns=""?
Thanks