Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:53:56+00:00 2026-05-27T07:53:56+00:00

i need to get this url (http://localhost:8983/solr/select/?q=treen&omitHeader=true) and get the response as xml, and

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:53:57+00:00Added an answer on May 27, 2026 at 7:53 am

    You should be able to use something like:

    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 ) ]
      }
    }
    

    Given your example xml, at the end of that function, map_ should be equal to:

    [ "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) ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have URL like this: http://localhost/PMApp/temp.htm?ProjectID=462 What I need to do is to get
For example i have this xml. I need to get value of parameter val
I have a url which normally points to a postcode lookup webservice: http://localhost/afddata.pce?Serial=xxxxxx&Password=<PASSWORD>&UserID=<UNAME>&Data=Address&Task=PropertyLookup&Fields=List&MaxQuantity=200&Lookup=BD1+3RA I
I have the following url: http://localhost:58124/Tag/GetData?filter(Tag)=contains(112)&filter(Process)=contains(112)&page=0&pageSize=30 If I declare my action result like this
I have a url that looks like this: http://localhost/store/mens/category/t-shirts/item/a-t-shirt I have a class called
I have this string: 123-456-7 I need to get this string: 1234567 How I
I need to get a value from another page. But I get this error
I've been trying to get this code to work for hours! All I need
I need to get UserCarId(int) from this query and assign to int type variable.
We have this set of data that we need to get the average of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.