wslite SOAPResponse - 获取完整 XML 响应的特定部分作为字符串

wslite SOAPResponse - Get Certain Part of the Complete XML Response as String

我目前正在使用 wslite 库来帮助我使用 SOAP Web 服务。 在我的 SOAPResponse 中,我可以使用它的 text 属性 得到类似 的东西

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
     <soap:Body>
          <GetPriceResponse xmlns:"http://www.w3schools.com/prices">
              <Price>1.90</Price>
          </GetPriceResponse>
     </soap:Body>
</soap:Envelope>

顺便说一句,我从 here 那里拿了这个样本。

我的问题是我真的只想获取主要内容作为 String。在这种情况下,它应该是:

<GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
     <Price>1.90</m:Price>
</GetPriceResponse>

我试过这样的事情:

SOAPClient client = new SOAPClient(service)
def response = client.send(SOAPAction: action) {
     Method(xmlns: namespace)
}
println XmlUtil.serialize(response.body.'*' as GPathResult)

但不知何故,我设法得到了一些东西 比如:

<tag0:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
     <tag0:Price>1.90</tag0:Price>
</tag0:GetPriceResponse>

它在某种程度上与 XmlUtil 的命名空间意识有关。但我不认为 serialize 方法提供了一个我可以关闭它的重载。还有另一种方法吗?我只需要正文内容 String,真的。我愿意使用其他方法。但现在,我不确定该怎么做。使用 StreamingMarkupBuilder 做同样的事情。我在每个标签中都有 tag0 个前缀。

最后,我使用了 StreamingMarkUpBuilder 并且我不得不在绑定闭包中包含 mkp.declareNamespace ('prefix', 'namespace') 。在我的例子中,为了防止它生成自己的命名空间前缀(比如 tag0),我这样做了:

String xml = new StreamingMarkupBuilder().bind { 
     mkp.declareNamespace('': 'http://www.w3schools.com/prices') 
     ...
}