Windows Phone App needs to read in from xml source

Issues with trying to fill a list with values from an XML source.

I have a WebClient to read into the project which calls the function below.

WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
Uri url = new Uri("", UriKind.Absolute);

The function

public void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        var xml = XDocument.Load(e.Result);

        var results = from row in xml.Element("value").Elements() select row;
        // now I loop all rows and print the title; of course you canfc
        // do other stuff here or combine some data processing with the LINQ above
        // - this is up to you
        foreach (var result in results)
            item.ItemLine1 = result.Value;
     catch (Exception c)

The list elements return a null reference.

Here's what the XML file looks like

  <value>Fall 2013</value> 
  <value>Third Summer 2013</value> 

Not having too much luck with the xml file. Any help is appreciated.


A couple of thoughts:

  1. Replace XDocument.Load(e.Result) with XDocument.Parse(e.Result). XDocument.Load() treats is argument as a URI, and you have -- I assume -- already downloaded the XML document. XDocument.Parse() cracks open that document for you.

  2. Try the following:

    var results = from row in xml.Root.Elements("row")
                  select row.Element("value");

    XElement.Elements() only works from the current XML element -- it doesn't scan the entire XML document tree. To scan the entire tree, you can use XElement.Descendants(). Or, to more precisely pick the elements you need, use the pattern as above -- pick elements from the first level, then go deeper into the next level.

Need Your Help

Passing a specific shape as a function argument

variables powerpoint argument-passing shapes

Using Powerpoint 2010 and MS Visual Basic for applications: