I have following xml file:
<doc_xml>
<nodes>
<node id='1' spec="{spec_a=0.9, spec_b=0.1}" />
<node id='2' spec="{spec_a=0.1, spec_b=0.3}" />
<node id='3' spec="{}" />
</nodes>
</doc_xml>
This code was created using Groovy MarkupBuilder.
Now I would like to parse this file in a groovy script:
def xml = new XmlParser().parseText(getDocXmlAsString());
xml.nodes.node.each {
Map spec = it.@spec; // here I got an exception org.codehaus.groovy.runtime.typehandling.GroovyCastException
}
but I keep getting this exception:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{spec_a=0.9, spec_b=0.1}' with class 'java.lang.String' to class 'java.util.Map'
My question, how to parse an xml attribute which is a map?