I am writing a test case where my response could be of one the below two formats
<Amount currency="USD" xsi:Type="cc:MoneyType">"10.00"</Amount>
or
<Amount xsi:Type="cc:MoneyType" currency="USD">"10.00"</Amount>
And my code for finding the currency
attribute value and value of amount
is as follows,
Pattern pattern = Pattern.compile("<Amount currency=\"(\\S+)\" xsi:type=\"cc:Money\">(\\S+)</Amount>");
Matcher matcher = null;
Double sumOfAmount = 0.0;
String currency = null;
matcher = pattern.matcher(response);
while(matcher.find()) {
currency = matcher.group(1);
sumOfAmount += Double.valueOf(matcher.group(2));
}
But this code works only for the first format of the response, how should I change it to work to match the second type of format as well. In other words, ignore the ordering of the attributes.