English 中文(简体)
CNET XML处理通过XDocument。后代未按预期提取实体
原标题:C#.NET XML Processing via XDocument.Descendants not fetching entities as expected

使用XDocumentDescendants方法。

//first problem  entries  doesn t fetch at all
var entries = xmlDoc.Descendants(XName.Get("entry"))
//neither does
//            xmlDoc.Descendants("entry")

var ids = from e in entries 
          select e.Element(XName.Get("id")).Value;

相同的XDocument代码适用于更详细的博客提要,即我的博客:http://blog.nick.josevski.com/feed/此处有一个片段:http://pastebin.com/KU65dgwL其中entry元素被替换为item,id被替换为link。

为了测试任何建议,我创建了一个演示该问题的LinqPad代码要点

我是不是错过了一些显而易见的东西?我尝试过各种<code>的组合。元素()。元素(“entry”)和仅。Descendants(),然后尝试进一步过滤,但也没有运气。

这是我正在努力从中提取entry/id节点的XML:

<feed xmlns="http://www.w3.org/2005/Atom">
    <title type="text">Author</title>
    <subtitle type="text">subtitle</subtitle>
    <link rel="alternate" href="http://www.site.com/blog" />
    <entry>
        <id>http://www.site.com/a-blog-post</id>
        <title type="text">Title Of Blog Post</title>

    ...

    <entry>
        <id>http://www.site.com/another-blog-post</id>
        <title type="text">Title Of Another Blog Post</title>
最佳回答

您缺少XML命名空间:

XNamespace ns = "http://www.w3.org/2005/Atom";
var entries = xmlDoc.Descendants(ns + "entry");
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签