Read single node from XML file into listBox (WP7, Silverlight, C#) -
i want take names of similar artists url below, , display them in listbox.
http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=artistnamehere&api_key=ff1629a695c346cc4b2dd1c41fcd4054
so far other people's questions here i've got read xml file:
private void phoneapplicationpage_loaded(object sender, routedeventargs e) { webclient wc = new webclient(); wc.downloadstringcompleted += httpcompleted; wc.downloadstringasync(new uri("http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=artistnamehere&api_key=ff1629a695c346cc4b2dd1c41fcd4054")); } private void httpcompleted(object sender, downloadstringcompletedeventargs e) { if (e.error == null) { xdocument xdoc = xdocument.parse(e.result, loadoptions.none); // xdocument here } }
as said before, want take artist names page, each of name nodes , display them in listbox. how go doing this?
this should it:
xelement artists = xdoc.root.element("similarartists"); if (artists != null) { ienumerable<string> names = artists .elements("artist") .select(el => el.element("name").value); }
it uses methods system.xml.linq
namespace used retrieve xml info using linq.
c# xml silverlight windows-phone-7 linq-to-xml
No comments:
Post a Comment