Search code examples
xmlparsinggroovyparsexml

Groovy parse xml


I'm a newbie in groovy Can anyone help to parse this xml in order to get a list of values of the each num element

 NAMES>
    <NAMESet fetchSize="3">
    <String StringNumber="1">
        <NUM>1</NUM>
    </String>
    <String StringNumber="2">
        <NUM>2</NUM>
    </String>
    <String StringNumber="3">
        <NUM>3</NUM>
</NAMESet>

thanks in advance!


Solution

  • finally, wrote like this:

    def records = new XmlParser().parseText(xml)
    def size = records.ResultSet.Row.ID.size()
    println(size)
    def allRecords = records.ResultSet.Row.ID[1].text()
    println(allRecords)
    for (int i = 0; i < size; i++) {
    println(records.ResultSet.Row.ID[i].text())
    }
    

    anyway, thanks