我有一个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>
最佳答案
试试这个:
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);
// ...
关于java - 如何更改 SOAPBODY 中的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20885825/