[英]Getting specific Xml node
我如何從該提要中獲取“入口”節點
http://www.google.com/alerts/feeds/14392773026536511983/5526937985735563348
我嘗試了linq到xml,但是我認為由於以下代碼無法訪問條目標簽的現有屬性。
string url = "http://www.google.com/alerts/feeds/14392773026536511983/5526937985735563348";
WebClient c = new WebClient();
string xml = ASCIIEncoding.Default.GetString(c.DownloadData(url));
XDocument doc = XDocument.Parse(xml);
var entries = doc.Descendants("entry");
提前致謝,
您未指定名稱空間。 嘗試這個:
XNamespace atom = "http://www.w3.org/2005/Atom";
var entries = doc.Descendants(atom + "entry");
順便說一句,我不會為此使用ASCII或DownloadData
...使用WebClient.DownloadString
為您處理編碼。 或者實際上,只需使用XDocument.Load(url)
:
例如:
string url = ...;
XDocument doc = XDocument.Load(url);
XNamespace atom = "http://www.w3.org/2005/Atom";
var entries = doc.Descendants(atom + "entry");
Console.WriteLine(entries.Count()); // Prints 20
此數據以Atom格式顯示,因此您需要根據標准規范對其進行解析。 最簡單的方法是看一下開源代碼。 簽出此鏈接 ,您需要“為Atom,RDF和RSS feed創建通用解析器”部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.