0

Given an xml like

<foo>
 <bar>1</bar>
 <bar>2</bar>
</foo>

I would like to get all the values from a

String tagName = "bar"
List<Sting> bars = xmlPath.get(String.format("**.findAll {it.name() == '%s' }", tagName));

It is working when i have multiple bar nodes in the response xml. But when i got only one node then xmlPath.get("**.findAll....") returns only a single String value, and Java throws exception

Any idea how to tell Groovy "**.findAll...." to return List with one element in case there is only one match in the prediction?

1 Answers1

1

It is working with getList()

String tagName = "bar"
List<Sting> bars = xmlPath.getList(String.format("**.findAll {it.name() == '%s' }", tagName));