如何在Java中将肥皂子元素添加到肥皂主体

时间:2019-01-30 09:08:54

标签: java soap

我正在尝试使用addChildElement方法在SOAP Element对象上构建SOAP主体,但我不明白如何构造

之类的子元素
<recipient-collection xtkschema="nms:recipient">

我了解addChildElement方法支持3个参数作为组合-字符串,前缀,URI。但这不能解决我的问题。

我正在尝试使用javax.xml.soap包调用SOAP服务,下面是我目前用于创建SOAP正文的代码。

SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("WriteCollection", myNamespace);
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("sessiontoken", myNamespace);
soapBodyElem1.addTextNode("abc/abc");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("domDoc", myNamespace);
SOAPElement soapBodyElem21 = soapBodyElem2.addChildElement("recipient-collection");
SOAPElement soapBodyElem211 = soapBodyElem21.addChildElement("recipient");
soapBodyElem211.addTextNode("abc@mail.com");
SOAPElement soapBodyElem212 = soapBodyElem21.addChildElement("recipient");
soapBodyElem212.addTextNode("xyz@mail.com");

下面是预期的SOAP主体,我在构造“收件人收集”标记作为SOAP元素时遇到了问题。

<soapenv:Body>
    <urn:WriteCollection>
    <urn:sessiontoken>abc/abc</urn:sessiontoken>
    <urn:domDoc>
        <recipient-collection xtkschema="nms:recipient">
            <recipient>abc@mail.com</recipient>
            <recipient>xyz@mail.com</recipient>
        </recipient-collection>
    </urn:domDoc>
</urn:WriteCollection>
</soapenv:Body>

0 个答案:

没有答案