wslite SOAPResponse—将完整XML响应的某些部分作为字符串获取
我目前正在使用该库来帮助我使用SOAP web服务。 在我的中,我可以使用它的wslite SOAPResponse—将完整XML响应的某些部分作为字符串获取,xml,string,soap,groovy,prefix,Xml,String,Soap,Groovy,Prefix,我目前正在使用该库来帮助我使用SOAP web服务。 在我的中,我可以使用它的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>
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>
我试过这样做:
但不知怎的,我设法得到了这样的东西:
1.90
它在某种程度上与
XmlUtil
的名称空间意识有关。但是我不认为serialize
方法提供了一个重载,我可以在这里设置它。还有别的办法吗?我只需要正文内容字符串
,真的。我愿意使用其他方法。但现在,我不知道该怎么办。使用StreamingMarkupBuilder
也可以执行相同的操作。我在每个标记中得到tag0
前缀。最后,我使用了StreamingMarkUpBuilder
,我必须在绑定闭包中包含mkp.declareNamespace('prefix','namespace')
。在我的例子中,为了防止它生成自己的名称空间前缀(如tag0)
,我这样做了:
String xml = new StreamingMarkupBuilder().bind {
mkp.declareNamespace('': 'http://www.w3schools.com/prices')
...
}
如果您有名称空间前缀,会出现什么问题?我正在尝试(使用JAXB)解组该类。它不能与我的注释一起使用。
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>
String xml = new StreamingMarkupBuilder().bind {
mkp.declareNamespace('': 'http://www.w3schools.com/prices')
...
}