2015-08-13 46 views
-1

這是我從soapui獲得的響應。groovy-如何獲得響應數組中的相同字段的值

<PageList> 
    <offset>0</offset> 
    <totalLength>2</totalLength> 
    <result> 
    <Id>9</Id> 
    <Name>Cake</Name> 
    <Price>80</Price> 
    <quantity>1</quantity> 
    </result> 
    <result> 
    <Id>13</Id> 
    <Name>Tea</Name> 
    <Price>10</Price> 
    <quantity>5</quantity> 
    </result> 
    <result> 
    <Id>15</Id> 
    <Name>Cofee</Name> 
    <Price>15</Price> 
    <quantity>10</quantity> 
    </result> 
</PageList> 

如何顯示名稱字段分別像 蛋糕,茶,COFEE 使用Groovy腳本

+0

你有沒有嘗試什麼?基本上,文檔中的大多數示例都會告訴您如何執行此操作。 –

回答

1

你可以得到名稱以下列方式列表:

def xml = '''<PageList> 
    <offset>0</offset> 
    <totalLength>2</totalLength> 
    <result> 
    <Id>9</Id> 
    <Name>Cake</Name> 
    <Price>80</Price> 
    <quantity>1</quantity> 
    </result> 
    <result> 
    <Id>13</Id> 
    <Name>Tea</Name> 
    <Price>10</Price> 
    <quantity>5</quantity> 
    </result> 
    <result> 
    <Id>15</Id> 
    <Name>Cofee</Name> 
    <Price>15</Price> 
    <quantity>10</quantity> 
    </result> 
</PageList>''' 

def slurped = new XmlSlurper().parseText(xml) 
def names = slurped.result.Name.collect { it.text() } 
println names 
+0

我無法將此值傳遞給另一個測試請求 – sachu

+0

@Reshu,這是一個不同的問題。你在問如何獲得價值。 – Opal

相關問題