Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy - XmlSlurper - read attributes into a Map

<racebet amount="8.89" id="6852465" bettype="K" instance="1" type="csf" />

What is the best way to create a map containing the attributes as keys and the corresponding values?

thanks.

like image 660
saravana_pc Avatar asked Apr 30 '14 15:04

saravana_pc


1 Answers

Given:

def xml = '<racebet amount="8.89" id="6852465" bettype="K" instance="1" type="csf" />'

You can simply do:

def attrmap = new XmlSlurper().parseText( xml ).attributes()
like image 70
tim_yates Avatar answered Oct 21 '22 16:10

tim_yates