我想从以下 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") 它也没有显示任何异常。如果我有任何错误,请纠正我。