i need to get this url (http://localhost:8983/solr/select/?q=treen&omitHeader=true) and get the response as xml, and for each record, parse it to a class and then create a final map with all the info. Something like this:
class SolrController {
def solr= {
def map_ = [:]
def json = grails.converters.XML.parse( new URL( 'http://localhost:8983/solr/select/?q=treen&omitHeader=true' ).text)
json.each{
Wikidoc aa = new wikiDoc(id: it.id, title: it.title)
map_.put(aa.id, aa)
}
}
}
class wikiDoc{
String id
String title
}
The xml is the following:
<response>
<result name="response" numFound="18" start="0">
<doc>
<str name="id">2722092</str>
<arr name="title">
<str>David Treen</str>
</arr>
</doc>
<doc>
<str name="id">3380835</str>
<arr name="title">
<str>Eleição para governador da Luisiana em 1979</str>
</arr>
</doc>
<doc>
<str name="id">3380827</str>
<arr name="title">
<str>Eleição para governador da Luisiana em 1983</str>
</arr>
</doc>
<doc>
<str name="id">2722798</str>
<arr name="title">
<str>Edwin Edwards</str>
</arr>
</doc>
<doc>
<str name="id">1791213</str>
<arr name="title">
<str>Predefinição:Governadores da Luisiana</str>
</arr>
</doc>
<doc>
<str name="id">2941389</str>
<arr name="title">
<str>Career (filme de 1959)</str>
</arr>
</doc>
<doc>
<str name="id">1969582</str>
<arr name="title">
<str>Kitty Foyle</str>
</arr>
</doc>
<doc>
<str name="id">2148082</str>
<arr name="title">
<str>Christmas with the Kranks</str>
</arr>
</doc>
<doc>
<str name="id">2077295</str>
<arr name="title">
<str>The Sad Sack</str>
</arr>
</doc>
<doc>
<str name="id">2765563</str>
<arr name="title">
<str>David Vitter</str>
</arr>
</doc>
</result>
</response>
I would apreciate help with this, i don’t see how can it be done, because can’t acess, for example, json[1].id
Thanks in adv,
RR
You should be able to use something like:
Given your example xml, at the end of that function,
map_should be equal to: