c# can't get attributes out of xml -
i have problem im trying values attributes of xml file 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 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 can me, thanks.
id, gametitle, releasedate
, platform
elements under game
, viz:
id = int.parse(x.element("id")), gametitle = (string)x.element("gametitle"), releasedate = (string)x.element("releasedate"), platform = (string)x.element("platform")
you'll need parse int.
Comments
Post a Comment