I am calling a service and I get the XML response in the below format.
How do I retrieve multiple values under a single key from this response?
I want to store all the values in a List<String>
<p700:item xmlns:p700="http://abc.test.com">
<p700:key xsi:type="xsd:string">Key1</p700:key>
<p700:value xsi:type="xsd:string">Value1</p700:value>
<p700:value xsi:type="xsd:string">Value2</p700:value>
<p700:value xsi:type="xsd:string">Value3</p700:value>
<p700:value xsi:type="xsd:string">Value14</p700:value>
</p700:item>
<p700:item xmlns:p700="http://abc.test.com">
<p700:key xsi:type="xsd:string">Key1</p700:key>
<p700:value xsi:type="xsd:string">Value1</p700:value>
<p700:value xsi:type="xsd:string">Value2</p700:value>
</p700:item>
Guava has a
Multimapinterface and aListMultimapimplementation, which is a map of keys to multiple values contained in a list structure (as opposed to a set or sorted set). It’s essentially aMap<K, Collection<V>>. You can also find examples here. As for actually parsing the XML, there are a number of questions about that here on SO, and you can start with this one.