【发布时间】:2017-08-29 18:52:20
【问题描述】:
我想在 Soap 请求的正文中添加子元素(标识符),如下所示:
预期的肥皂请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="nsurl">
<soapenv:Header/>
<soapenv:Body>
<ns:GetRequest>
<ns:Identifier Type="x" Value="y"/>
</ns:GetRequest>
</soapenv:Body>
</soapenv:Envelope>
使用我的代码,我可以添加子元素(标识符),如下所示:
实际肥皂请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="nsurl">
<soapenv:Header/>
<soapenv:Body>
<ns:GetRequest>
<ns:Identifier>Type="x" Value="y"</ns:Identifier>
</ns:GetRequest>
</soapenv:Body>
</soapenv:Envelope>
这里是java代码:
private static void createSoapEnvelope(SOAPMessage soapMessage) throws SOAPException {
SOAPPart soapPart = soapMessage.getSOAPPart();
String myNamespace = "ns";
String myNamespaceURI = "nsurl";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration(myNamespace, myNamespaceURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("GetRequest", myNamespace);
SOAPElement soapBodyElem1 =soapBodyElem.addChildElement("Identifier", myNamespace);
soapBodyElem1.addTextNode("Type=\"x\" Value=\"y\"");
}
【问题讨论】:
标签: java soap groovy soapui saaj