0

这就是我要的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tps="http://mysite.it">
   <soapenv:Header/>
   <soapenv:Body>
      <tps:getBook>
         <tps:id>45</tps:id>
      </tps:Retrieve_getBook_Poi_Recordset>
   </soapenv:Body>
</soapenv:Envelope>

但这是我有的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tps="http://mysite.it">
   <soapenv:Header/>
   <soapenv:Body>
      <tps:getBook xmlns:tps="http://mysite.it">
         <tps:id xmlns:tps="http://mysite.it">45</tps:id>
      </tps:Retrieve_getBook_Poi_Recordset>
   </soapenv:Body>
</soapenv:Envelope>

我正在使用 javax.xml.soap.* 创建肥皂消息...我找不到在 param 标记中仅插入前缀的方法。

这是生成肥皂消息的代码:

MessageFactory msgFactory = null;
SOAPMessage message = null;
msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
message = msgFactory.createMessage();
SOAPEnvelope messageEnvelope = message.getSOAPPart().getEnvelope();
SOAPBody messageBody = messageEnvelope.getBody();

messageEnvelope.addNamespaceDeclaration(PREFIX, getNameSpace(method));

SOAPElement soapMethod = messageBody.addChildElement(method, PREFIX);
SOAPElement param = soapMethod.addChildElement("id",PREFIX);
param.addTextNode("45");

我该怎么做才能只删除命名空间?

4

1 回答 1

1

对于元素和属性节点:

Node node = ...;
String name = node.getLocalName();

将为您提供节点名称的本地部分。

正如您所提到的,您真的不想从 XML 中删除名称空间信息。对于您的特定情况,这是一个很好的解决方法,但我会保持名称空间信息不变。

于 2013-06-21T19:59:37.767 回答