Contributions
Re: How to iterate through XML response with Groovy
HelloKondasamy, Thank you for your response, I get the idea that I can use holder.getNodeValues("//document-group") toretrieveall the document-group in the XML, but how would i go about retrieve just the <document-group> that are within the <available-document> ? the reason is that I will have multiple<available-document> and the number of time it appears in the response will change, now the idea is to iterate through all the<available-document> in the XML and in each <available document> i would like to iterate through the XML and retrievethe <document-group> that are in it. I wasnt having any solution on how would I go about nested iteration. Thank you8 years agoPlace ReadyAPI QuestionsReadyAPI Questions9KViews0likes1CommentHow 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:Documenttwo 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 appreciated8 years agoPlace ReadyAPI QuestionsReadyAPI Questions9.2KViews0likes3Comments