获取特定的Xml节点

发布于 2024-10-26 12:47:19 字数 720 浏览 4 评论 0原文

如何从此提要中获取“入口”节点

http://www.google.com/alerts/feeds/14392773026536511983/5526937985735563 348< /a>

我尝试了 linq to 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");

提前致谢,

How can I get "entry" nodes from this feed

http://www.google.com/alerts/feeds/14392773026536511983/5526937985735563348

I tried linq to xml but I think because of the existing attributes of entry tags following code does not work.

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");

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2024-11-02 12:47:19

您没有指定名称空间。试试这个:

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

You're not specifying a namespace. Try this:

XNamespace atom = "http://www.w3.org/2005/Atom";
var entries = doc.Descendants(atom + "entry");

Btw, I wouldn't use ASCII for this, or DownloadData... use WebClient.DownloadString to handle the encoding for you. Or indeed, just use XDocument.Load(url):

For example:

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
贪了杯 2024-11-02 12:47:19

这些数据以 Atom 格式呈现,因此您需要根据标准规范对其进行解析。最简单的方法是查看开源代码。查看此链接,您需要“为 Atom 创建通用解析器” 、RDF 和 RSS feed”部分

This data presented in Atom format, so you need to parse it according to the standard specification. The simplest way is take a look on to open source code. Check out This link, you are need "Creating a generic parser for Atom, RDF and RSS feeds" part

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文