LINQ到XML:结肠中的XML标记问题结肠、标记、问题、LINQ

2023-09-04 04:50:19 作者:ˉ﹏谨此而已〞

这里的code来检索内容标记值:

Here's the code to retrieve the value in the content tag:

   var returnVerse = from item in xmlTreeVerse.Descendants("rss").Elements("channel").Elements("item")
                              select new VerseModel
                               {
                                   Verse = item.Element("content").Value,
                                   Url = ""
                               };

下面的XML文件:

<?xml version="1.0" ?>
<rss version="2.0"
                    xmlns:dc="http://purl.org/dc/elements/1.1/"
                    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
                    xmlns:admin="http://webns.net/mvcb/"
                    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                    xmlns:content="http://purl.org/rss/1.0/modules/content/">

  <channel>
    <title>text</title>
    <link>text</link>
    <item>
      <title>text</title>
      <content:encoded>
        Text
      </content:encoded>
    </item>
  </channel>
</rss>

我无法查询的内容:恩code,因为它是无效的查询:操作符。请大家帮帮忙。

I can't query "content:encode" because it is invalid to query the ":" operator. Please help.

推荐答案

这是冒号经营者是一个命名空间。你需要有一个命名空间来查询为好。您可以使用命名空间是这样的:

That "colon operator" is a namespace. You need to query with a namespace as well. You use namespaces like this:

XNamespace content = XNamespace.Get("http://purl.org/rss/1.0/modules/content/");
Verse = item.Element(content + "encoded").Value