如何使用 linq to xml 解析此 XML?
我正在尝试解析以下 xml,但没有成功,没有人指导我我在这里犯了什么错误,
string feedURL = "http://www.bbc.co.uk/arabic/index.xml";
XDocument feedSource;
feedSource = XDocument.Load(feedURL);
var another = (from myFeed in feedSource.Descendants("entry")
select new
{
feedTitle = myFeed.Element("title").Value,
//feedDescription = myFeed.Element("description").Value,
//feedLink = myFeed.Element("link").Value,
feedpubDate = myFeed.Element("published") != null ? myFeed.Element("published").Value : null
//feedcategory = myFeed.Element("category") != null ? myFeed.Element("category").Value : null,
//feedItems = myFeed.Descendants("entry")
}
);
if (another != null && another.Count() > 0)
{
}
else
{
Response.Write("No Record Found");
}
它显示没有找到任何记录。
任何帮助将不胜感激。
i am trying to parse following xml but no sucess any one guide me what mistake am i doing here
string feedURL = "http://www.bbc.co.uk/arabic/index.xml";
XDocument feedSource;
feedSource = XDocument.Load(feedURL);
var another = (from myFeed in feedSource.Descendants("entry")
select new
{
feedTitle = myFeed.Element("title").Value,
//feedDescription = myFeed.Element("description").Value,
//feedLink = myFeed.Element("link").Value,
feedpubDate = myFeed.Element("published") != null ? myFeed.Element("published").Value : null
//feedcategory = myFeed.Element("category") != null ? myFeed.Element("category").Value : null,
//feedItems = myFeed.Descendants("entry")
}
);
if (another != null && another.Count() > 0)
{
}
else
{
Response.Write("No Record Found");
}
it is showing me no record found.
any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在 LINQPad 中有效:
问题是缺少命名空间。
This worked in LINQPad:
Problem was the lacking namespace.