I am trying to parse some XML in my program, but I cannot seem to figure out the best way to do this.
The XML has an element called “container”. This element has multiple descendants called “text”. What I would like to do is pull out the values inside the “text” elements, in order, and save them in a string.
So the XML looks like :
<containers>
<container>
<elt3243> </elt3243>
<elt1122></elt1122>
<elt><text> Put me in a string please </text> </elt>
<elt2211></elt2211>
</container>
<container>
<elt3243><text>I would also like to be in the string</text></elt3243>
<elt1122></elt1122>
<elt> </elt>
<elt2211></elt2211>
</container>
</containers>
And the result I would like :
String result = "Put me in a string please \n I would also like to be in the string";
What is the best way of doing this ?
1 Answer