C# Linq XML API

bbnova

New Member
I'm trying to use an Formula 1 API for a WP7 application. I can't find the correct way to select the correct nodes and elements. What is the right way ? This is the xml: ergast.com/api/f1/2012/driversDriversPage.xaml.cs\[code\]using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;using System.Xml.Linq;namespace Formule1{public partial class DriversPage : PhoneApplicationPage{ const string URL = "http://ergast.com/api/f1/2012/"; public DriversPage() { InitializeComponent(); GetDrivers(); } private void GetDrivers() { string resource = "drivers"; WebClient webclient = new WebClient(); webclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webclient_DownloadStringCompleted); webclient.DownloadStringAsync(new Uri(URL + resource)); } private void webclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { return; } // xml-resultaat parsen XDocument xmlEntries = XDocument.Parse(e.Result); List<Driver> drivers = new List<Driver>(); drivers = (from element in xmlEntries.Root.Element("DriverTable").Descendants("Driver") select new Driver(element.Attribute("driverId").Value)).ToList<Driver>(); DriverListBox.ItemsSource = drivers; } }}\[/code\]API\[code\]<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="http://ergast.com/schemas/mrd-1.2.xsl"?><MRData xmlns="http://ergast.com/mrd/1.2" series="f1" url="http://ergast.com/api/f1/2012/drivers" limit="30" offset="0" total="24"> <DriverTable season="2012"> <Driver driverId="alonso" url="http://en.wikipedia.org/wiki/Fernando_Alonso"> <GivenName>Fernando</GivenName> <FamilyName>Alonso</FamilyName> <DateOfBirth>1981-07-29</DateOfBirth> <Nationality>Spanish</Nationality> </Driver> <Driver driverId="button" url="http://en.wikipedia.org/wiki/Jenson_Button"> <GivenName>Jenson</GivenName> <FamilyName>Button</FamilyName> <DateOfBirth>1980-01-19</DateOfBirth> <Nationality>British</Nationality> </Driver> <Driver driverId="rosa" url="http://en.wikipedia.org/wiki/Pedro_de_la_Rosa"> <GivenName>Pedro</GivenName> <FamilyName>de la Rosa</FamilyName> <DateOfBirth>1971-02-24</DateOfBirth> <Nationality>Spanish</Nationality> </Driver> <Driver driverId="resta" url="http://en.wikipedia.org/wiki/Paul_di_Resta"> <GivenName>Paul</GivenName> <FamilyName>di Resta</FamilyName> <DateOfBirth>1986-04-16</DateOfBirth> <Nationality>Scottish</Nationality> </Driver> <Driver driverId="glock" url="http://en.wikipedia.org/wiki/Timo_Glock"> <GivenName>Timo</GivenName> <FamilyName>Glock</FamilyName> <DateOfBirth>1982-03-18</DateOfBirth> <Nationality>German</Nationality> </Driver> <Driver driverId="grosjean" url="http://en.wikipedia.org/wiki/Romain_Grosjean"> <GivenName>Romain</GivenName> <FamilyName>Grosjean</FamilyName> <DateOfBirth>1986-04-17</DateOfBirth> <Nationality>French</Nationality> </Driver> <Driver driverId="hamilton" url="http://en.wikipedia.org/wiki/Lewis_Hamilton"> <GivenName>Lewis</GivenName> <FamilyName>Hamilton</FamilyName> <DateOfBirth>1985-01-07</DateOfBirth> <Nationality>British</Nationality> </Driver> <Driver driverId="hulkenberg" url="http://en.wikipedia.org/wiki/Nico_H%C3%BClkenberg"> <GivenName>Nico</GivenName> <FamilyName>H
 
Back
Top