Вы должны иметь возможность использовать что-то вроде:
def solr= {
def json = grails.converters.XML.parse( new URL( 'http://localhost:8983/solr/select/?q=treen&omitHeader=true' ).text )
// Start with [:] for every doc element e perform the closure
def map_ = json.result.doc.inject( [:] ) { map, e ->
// For this doc element, find the str element with name='id', and get its text()
String id = e.str.find { it.@name == 'id' }.text()
// then, find the arr element with name='title', and get the text() from the str element within
String title = e.arr.find { it.@name == 'title' }.str.text()
// Then, push this new map entry into our current map
map << [ (id): new WikiDoc( id:id, title:title ) ]
}
}
Учитывая ваш пример xml, в конце этой функции map_
должно быть равно:
[ "2722092":WikiDoc(2722092, David Treen),
"3380835":WikiDoc(3380835, Eleição para governador da Luisiana em 1979),
"3380827":WikiDoc(3380827, Eleição para governador da Luisiana em 1983),
"2722798":WikiDoc(2722798, Edwin Edwards),
"1791213":WikiDoc(1791213, Predefinição:Governadores da Luisiana),
"2941389":WikiDoc(2941389, Career (filme de 1959)),
"1969582":WikiDoc(1969582, Kitty Foyle),
"2148082":WikiDoc(2148082, Christmas with the Kranks),
"2077295":WikiDoc(2077295, The Sad Sack),
"2765563":WikiDoc(2765563, David Vitter) ]