我使用速度模板来创建一个肥皂请求。我使用 jax-ws 框架来实现一个 Web 服务客户端。我已经连接了一个 SOAP 处理程序来拦截出站消息。
我正在尝试用计算的新正文替换正文内容。
我在处理程序中使用以下代码:
public boolean handleMessage(SOAPMessageContext context) {
boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
try {
if (outbound) {
SOAPMessage msg = context.getMessage();
SOAPPart sp = msg.getSOAPPart();
SOAPEnvelope env = sp.getEnvelope();
SOAPBody body = env.getBody();
body.normalize();
System.out.println(body.getValue());
NodeList list = body.getElementsByTagName("template");
if(list.getLength() > 0) {
Element template = (Element) list.item(0);
if (template != null) {
String newBody = StringEscapeUtils.unescapeHtml(template.getTextContent());
Document bodyElement = XmlUtils.getDocumentFromText(newBody);
body.removeContents();
body.addDocument(bodyElement);
当我执行它时,我收到以下错误:
org.w3c.dom.DOMException: NAMESPACE_ERR: 试图以不正确的命名空间方式创建或更改对象。
如何轻松地从 xml 文本中更改正文内容?