def txt = """ <Lane_Attributes>
ID,1
FovCount,600
FovCounted,598
</Lane_Attributes> """
def map = new HashMap()
def lane = new XmlParser().parseText(txt)
def content = lane.text()
content.eachLine {
line ->
def dual = line.split(',')
def key = dual[0].trim()
def val = dual[1].trim()
//println "key: ${key} value: ${val}"
map.put(key,val)
}
println "map contains " + map.inspect()
// Will be printed: the card contains ["FovCounted": "598", "ID": "1", "FovCounted": "600"]
Your problem is that the content between the tags will have to support the same format in everything or this code will break
source
share