我有一个soapMessage,我正在写一个ByteArrayOutputStream来记录请求 但我必须在记录之前更改p803:Credential子元素值,我该怎么做?
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapMessageCtx.getMessage().writeTo(out);
这是请求xml
<soapenv:Body>
<p803:multiple xmlns:p803="http://www.abc.com/model">
<p803:RequestContext>
<p803:Credential>2222222/iuuiiiuuuu</p803:Credential>
答案 0 :(得分:2)
试试这个:
SOAPMessage soapMsg = soapMessageCtx.getMessage();
NodeList credentials = soapMsg
.getSOAPBody()
.getElementsByTagNameNS("http://rsi.chase.com/model", "Credential");
int len = credentials.length();
for(int i = 0; i < len; i++) {
credentials.item(i).setTextContent("new credential content goes here...");
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapMsg.writeTo(out);
// ...