如何从Groovy中的XML响应中读取十进制值?

时间:2013-06-25 08:46:56

标签: groovy soapui

我想阅读以下回复中的值:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
  <ConversionRateResponse xmlns="http://www.webserviceX.NET/">
     <ConversionRateResult>59.565</ConversionRateResult>
  </ConversionRateResponse>
</soap:Body>
</soap:Envelope>

我在下面的代码中尝试将值设为59.565,但我得到的是NULL:

def Xml = new XmlHolder(response)
def String rate = Xml.getNodeValue('//ConversionRateResponse/ConversionRateResult')
log.info(rate)

1 个答案:

答案 0 :(得分:2)

你可以尝试:

def xml = new XmlSlurper().parseText( response )
String rate = xml.Body.ConversionRateResponse.ConversionRateResult.text()