简体   繁体   中英

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.

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. This is a good workaround for your particular case, but I would leave the namespace info intact.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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