I have a problem where im trying to get the values from the attributes of a xml file from a url.
xml: http://thegamesdb.net/api/GetGamesList.php?name=x-men
code:
public MainPage()
{
InitializeComponent();
var webClient = new WebClient();
webClient.DownloadStringCompleted += RequestCompleted;
webClient.DownloadStringAsync(new Uri("http://thegamesdb.net/api/GetGamesList.php?name=x-men"));
}
private void RequestCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
var feedXml = XDocument.Parse(e.Result);
var gameData = feedXml.Root.Elements("Game").Select(x => new GetGamesList
{
// ERROR VALUES ARE NULL
ID = (int)x.Attribute("id"),
GameTitle = (string)x.Attribute("GameTitle"),
ReleaseDate = (string)x.Attribute("ReleaseDate"),
Platform = (string)x.Attribute("Platform")
})
.ToList();
}
}
public class GetGamesList
{
public int ID { get; set; }
public string GameTitle { get; set; }
public string ReleaseDate { get; set; }
public string Platform { get; set; }
}
I hope there is someone that can help me, thanks.