gpt4 book ai didi

c# - 聚合源 : How to access content:encoded?

转载 作者:太空狗 更新时间:2023-10-30 01:21:08 25 4
gpt4 key购买 nike

在 Windows 8 商店应用程序中,我正在使用 SyndicationFeed 读取一些 Xml 数据。 RSS 提要的一些项目包含例如 content:encoded (xmlns:content='...') 元素。我觉得没有办法通过SyndicationItem获取这些元素的内容吧?!

这就是为什么我在我的 foreach(SyndicationItem item in feeditems) 中尝试这样的事情:

item.GetXmlDocument(feed.SourceFormat).SelectSingleNode("/item/*:encoded]").InnerText;

但这行不通。而且我知道如何在 winrt 中使用 NamespaceManager 等。现在我正在访问 content:encoded 通过另一个元素的 NextSibling 方法,但这并不是一个真正干净的方法。

那么如何才能最好地访问元素的内容呢?

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="URI">
<channel>

<.../>

<item>
<title>Example entry</title>
<description>Here is some text containing an interesting description.</description>
<link>http://www.wikipedia.org/</link>
<content:encoded>Content I try to access</content:encoded>
</item>

</channel>
</rss>

最佳答案

只需使用XNamespace

XNamespace content = "URI";

var items = XDocument.Parse(xml)
.Descendants("item")
.Select(i => new
{
Title = (string)i.Element("title"),
Description = (string)i.Element("description"),
Link = (string)i.Element("link"),
Encoded = (string)i.Element(content + "encoded"), //<-- ***

})
.ToList();

关于c# - 聚合源 : How to access content:encoded?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16626570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com