How to iterate through XML response with Groovy
I'm new to Groovy scripting and right now i'm trying to accomplish a task which requires me to capture multiple data from an xml and convert it to such as a txt file or an excel file. I'm stuck at the step that how would i go about capture dynamic XML structure that might change in number every time i perform data source loop?
Better example:
I have a below XML which is from a respond
<available-document >
<document-code >123456</document-code >
<document-group>2</document-group>
<document-group>23</document-group>
<document-group>101</document-group>
<document-description lang="en">Document one name </document-description>
<legal-date>2013-08-22</legal-date>
</available-document>
<available-document>
<document-code>654321</document-code>
<document-group>6</document-group>
<document-description lang="ko">Document two name</document-description>
<legal-date>2013-08-30</legal-date>
</available-document>
so far I can capture all the values in a group by using below code:
for( item in holder.getNodeValues( "//document-description" ))
{
// loop item nodes in response message
log.info "Document name : [$item]"
file <<"|$item"
}
however that since each time the <document-group> number of times it appears in <available-document > changes, it will require me to capture all the <document-group> under <available-document >, the print out could look something like this.
code: 123456
group: 2, 23, 101
doc-desc: Document one name
date: 2013-08-22
code: 654321
group: 6
doc-desc: Document two name
date: 2013-08-30
my final plan is to use all these data and compare to the application UI by storing all these data in a txt file and read them through Test Complete , performing string manipulation to achieve the goal of comparing the data from XML to Application UI.
Thank you in advance, any help would be greatly appreciated