简体   繁体   English

SOAP-不带名称空间的前缀

[英]SOAP - Prefix without namespace

this is what I want: 这就是我要的:

<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>

but this is I have: 但这是我有:

<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>

I'm using javax.xml.soap.* to create soap message...and I cannot find a method to insert only prefix in param tag. 我正在使用javax.xml.soap。*创建肥皂消息...并且找不到在param标签中仅插入前缀的方法。

this is the code to generate soap message: 这是生成肥皂消息的代码:

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");

what can I do to remove only namespace? 我该怎么做才能仅删除名称空间?

For Element and Attribute nodes: 对于元素和属性节点:

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

will give you the local part of the node's name. 将为您提供节点名称的本地部分。

As you have mentioned, you really don't want to strip namespace info from your XML. 如前所述,您确实不想从XML中剥离名称空间信息。 This is a good workaround for your particular case, but I would leave the namespace info intact. 对于您的特定情况,这是一个很好的解决方法,但是我将保留名称空间信息不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM