2013-06-25 56 views
0

我想從下面的響應讀取值讀取十進制值:Groovy:在如何從XML響應

<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) 

幫助將不勝感激!

+0

完全無關的問題,但你並不需要做'DEF STRING rate',只是'字符串rate'將do' –

回答

2

你可以嘗試:

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

真棒..精湛的作品..感謝很多.. –