【发布时间】:2022-01-08 11:43:36
【问题描述】:
我正在调用第三方soap,其中每个元素都必须有一个命名空间。我正在从 Java 调用 .NET 服务。在某些元素中,我必须包含“http:/abc.com”。其他时候,我必须包含 xmlns:""。例如;
<GetYears xmlns="http://example.com">
<oCar xmlns="">
<make xmlns="http://example.com">Ford</make>
<model xmlns="http://example.com">F250</make>
</oCar>
</GetYears>
我正在使用 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);
默认情况下,这会产生以下输出,但会被服务拒绝,因为 oCar 上缺少命名空间“”。
<GetYears xmlns="http://example.com">
<oCar>
<make xmlns="http://example.com">Ford</make>
<model xmlns="http://example.com">F250</make>
</oCar>
</GetYears>
似乎忽略了一个空的命名空间。有没有办法强制元素包含 xmlns=""?
谢谢
【问题讨论】:
标签: java xml soap namespaces element