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 6367593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:34:05+00:00 2026-05-25T00:34:05+00:00

I am calling a restful service via the WebClient method to return some XML.

  • 0

I am calling a restful service via the WebClient method to return some XML. I would then like to parse through the XML, extract specific fields out of each node, and turn that into an array.

I have the code working to retrieve the XML and populate it into a listbox. For some reason I cannot work out how to turn that into an array of objects.

Code so far:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += HttpsCompleted;
        wc.DownloadStringAsync(new Uri(requestString));
    }

    private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);

            var data = from query in xdoc.Descendants("entry")
                       select new DummyClass
                       {
                           Name = (string)query.Element("title"),
                           Kitty = (string)query.Element("countryCode")
                       };
            listBox1.ItemsSource = data;
        }
    }

}

How can I turn each node into an object in an array?

Many thanks in advance!
Will.

EDIT: The XML looks like this:
http://api.geonames.org/findNearbyWikipedia?lat=52.5469285&lng=13.413550&username=demo&radius=20&maxRows=5

<geonames>
<entry>
<lang>en</lang>
<title>Berlin Schönhauser Allee station</title>
<summary>
Berlin Schönhauser Allee is a railway station in the Prenzlauer Berg district of Berlin. It is located on the Berlin U-Bahn line and also on the Ringbahn (Berlin S-Bahn). Build in 1913 by A.Grenander opened as "Bahnhof Nordring" (...)
</summary>
<feature/>
<countryCode>DE</countryCode>
<elevation>54</elevation>
<lat>52.5494</lat>
<lng>13.4139</lng>
<wikipediaUrl>
http://en.wikipedia.org/wiki/Berlin_Sch%C3%B6nhauser_Allee_station
</wikipediaUrl>
<thumbnailImg/>
<rank>93</rank>
<distance>0.2807</distance>
</entry>
</geonames>
  • 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-25T00:34:06+00:00Added an answer on May 25, 2026 at 12:34 am

    What is wrong with

    // convert IEnumerable linq query to an array
    var array = data.ToArray(); // could also use .ToList() for a list
    // access like this
    MessageBox.Show(array[0].Kitty);
    

    This will give you an array of DummyClass objects, from the IEnumerable<DummyClass> generated by the linq query.

    Additionally, an array may not even be required. If all you need to do is iterate over the data, you can simply do a foreach on your data object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to return a custom HTTP status code from a RESTful WCF
I am having a heck of a time calling a RESTful service from within
I am writing a RESTful web service where in I want to return a
I've got my MVC2 RESTFul webservice all set to accept JSON and return some
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
When calling a remote service (e.g. over RMI) to load a list of entities
When calling php via cli, the current directory is NOT changed to the one
Calling concat on vectors returns a list. Being a total noob I would expect
Calling all AutoMapper gurus! I'd like to be able to map object A to
Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a

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.