LINQ到XML:结肠中的XML标记问题 [英] Linq to XML : Problem with colon in the xml tags
本文介绍了LINQ到XML:结肠中的XML标记问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里的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
这篇关于LINQ到XML:结肠中的XML标记问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文