我試圖從http://b.fanfiction.net/atom/l/224/3/0/1/1/50/0/0/0/0解析RSS提要,但由於某種原因無法按元素名稱進行搜索。我遵循this page的指示,但他的示例似乎不適用於上面的粉絲站點。無法解析RSS提要
下面是我使用的代碼:通過運行
private void getData_Click(object sender, RoutedEventArgs e)
{
String rss = "http://b.fanfiction.net/atom/l/224/3/0/1/1/50/0/0/0/0";
HttpWebRequest request = HttpWebRequest.CreateHttp(rss);
request.BeginGetResponse(
asyncCallback =>
{
string data = null;
using (WebResponse response = request.EndGetResponse(asyncCallback))
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
data = reader.ReadToEnd();
}
}
Deployment.Current.Dispatcher.BeginInvoke(() => HttpsCompleted(data));
}
, null);
}
private void HttpsCompleted(string feedString)
{
// build XML DOM from feed string
XDocument doc = XDocument.Parse(feedString);
// show title of feed in TextBlock
XElement feed = doc.Element("feed");
XElement title = feed.Element("title");
String txt_title = title.Value;
txtBlk_FeedDescription.Text = txt_title;
// add each feed item to a ListBox
foreach (var item in doc.Descendants("entry"))
{
listBox1.Items.Add(item.Element("title").Value);
}
}
我試過剛剛上市的所有元素和文檔的子元素:
foreach (XElement element in doc.Elements())
{
txtBlk_FeedDescription.Text += element.Name.ToString() + "\n";
foreach (XElement subelement in element.Elements())
{
txtBlk_FeedDescription.Text += subelement.Name.ToString() + "\n";
}
}
這導致以下列表:
{http://www.w3.org/2005/Atom}喂
{http://www.w3.org/2005/Atom}筆者
{http://www.w3.org/2005/Atom}標題
{http://www.w3.org/2005/Atom}字幕
{http://www.w3.org/2005/Atom}鏈接
{http://www.w3.org/2005/Atom}更新
{http://www.w3.org/2005/Atom} ID
{http://www.w3.org/2005/Atom}條目
{http://www.w3.org/2005/Atom}項
{http://www.w3.org/2005/Atom}項
...
什麼我應該在這裏做任何幫助嗎?
謝謝!