次の URL から xml ファイルを解析したい:" http://restservice.com/RestServiceImpl.svc/ghhf/cvr "
次のコードを使用して XDocument を取得できます。
private void Search(object sender, RoutedEventArgs e)
{
string url = "http://restservice.schoolpundit.com/RestServiceImpl.svc/search_name/cvr";
WebClient twitter = new WebClient();
twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
twitter.DownloadStringAsync(new Uri(url));
}
void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XDocument doc = XDocument .Parse(e.Result);
var list = from child in doc.Descendants("Institutions_search_name")
select new listrows {
inst_name=doc.Element("Inst_name").Value;
};
Listbox.ItemSource=list;
}
しかし、それは Inst_name を表示していません。実際には、doc.Descendants("Institutions_search_name") に入っていません。例外も表示されていません。