Mis3
4 years agoFrequent Contributor
How to retrieve one particular parameter in an XML response of duplicate parameter name
Below is the response of an API I am working with. There are a few sections of <balance> with identical parameter names. Using this statement, def MESSAGE3 = xml.Body.GetSubscriberResponse.subscrib...
- 4 years agoHey Mis3,
Im on my phone so i cant try and replicate in ReadyAPI, but i notice youre not using indices in your xpath, hence the reason im guessing youre retrieving all the values that correspond to the code elements' values, rather than just a single value.
Im a bit out or practice cos ive been purely json for the last 3 years, but in your xpath:
xml.Body.GetSubscriberResponse.subscriber.balance.quota.code whereas i think if you add an index, this indicates which balance element is the correct parent in the tree for the code element value you want.
I cant really see the repeating structure properly on my phone and someone else will be able to confirm or deny this, but if in your xpath, rather than:
xml.Body.GetSubscriberResponse.subscriber.balance.quota.code
You instead add:
xml.Body.GetSubscriberResponse.subscriber.balance[1].quota.code then this will result in grabbing the code elements value that is a child of the first instance of the balance element (i.e. 'XPLOR_INTERNATIONAL')
Likewise if you wanted the 2nd code elements value:
xml.Body.GetSubscriberResponse.subscriber.balance[2].quota.code
This will result in grabbing the code elements value that is a child of the second instance of the balance element (i.e.'ROLLOVER_10')
Likewise if you wanted the 3rd code elements value:
xml.Body.GetSubscriberResponse.subscriber.balance[3].quota.code
This will result in grabbing the code elements value that is a child of the third instance of the balance element (i.e.'XPLOR_EXTENDED')
As i say....been quite a while since i was scripting with xml, but i remember its something like the above.
Hope this helps,
Rich