我正在使用凹槽和soapUI进行我的第一步:
我的问题是如何将矢量从soap响应转换为列表,然后断言vecorts元素的值。
响应就像那样
<![CDATA[<Vector>
<Object>
<pk>1</pk>
<valueA>B</valueA>
<valueB>20132</valueB>
</Object>
<Object>
<pk>2</pk>
<valueA>C</valueA>
<valueB>666</valueB>
</Object>
</Vector>]]>
此向量我想转换为List以将其与lokal列表进行比较,可能是这样的
def localCompare = new Arraylist[2]
def Objekt = new Array[3]
Objekt['pk'] = 1
Objekt['valueA'] = B
Objekt['valueB'] = 20132
localCompare.add(Objekt)
Objekt['pk'] = 2
Objekt['valueA'] = C
Objekt['valueB'] = 666
localCompare.add(Objekt)
assert localCompare.size() == 2
assert localCompare[1]['pk'] == 1
注意:我会在每个条目的循环中执行此操作,但我只是想表明我想将响应向量与本地值进行比较
答案 0 :(得分:0)
你也可以使用Groovy的XmlParser来处理响应数据
所以,首先解析xml 要以这种方式获取响应项:
groovy> def xml = '''<Vector>
groovy> <Object>
groovy> <pk>1</pk>
groovy> <valueA>B</valueA>
groovy> <valueB>20132</valueB>
groovy> </Object>
groovy> <Object>
groovy> <pk>2</pk>
groovy> <valueA>C</valueA>
groovy> <valueB>666</valueB>
groovy> </Object>
groovy> </Vector>'''
groovy> def records = new XmlParser().parseText(xml)
groovy> println records.Object.pk[0].text() //return from <pk>1</pk>
groovy> println records.Object.pk[1].text() //return from <pk>2</pk>
groovy> println records.Object.valueB[0].text() //return from <valueB>20132</valueB>
groovy> println records.Object.valueB[1].text() //return from <valueB>666</valueB>
groovy> println records.Object.valueA[0].text() //return from <valueA>B</valueA>
groovy> println records.Object.valueA[1].text() //return from <valueA>C</valueA>
Output:
1
2
20132
666
B
C
另外,请查看来源http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlParser