使用.net 3.5,有一个SyndicationFeed将加载到RSS源中,并允许您在其上运行LINQ.
以下是我正在加载的RSS示例:
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Title of RSS feed</title>
<link>http://www.google.com</link>
<description>Details about the feed</description>
<pubDate>Mon, 24 Nov 08 21:44:21 -0500</pubDate>
<language>en</language>
<item>
<title>Article 1</title>
<description><![CDATA[How to use StackOverflow.com]]></description>
<link>http://youtube.com/?v=y6_-cLWwEU0</link>
<media:player url="http://youtube.com/?v=y6_-cLWwEU0" />
<media:thumbnail url="http://img.youtube.com/vi/y6_-cLWwEU0/default.jpg" width="120" height="90" />
<media:title>Jared on StackOverflow</media:title>
<media:category label="Tags">tag1, tag2</media:category>
<media:credit>Jared</media:credit>
<enclosure url="http://youtube.com/v/y6_-cLWwEU0.swf" length="233" type="application/x-shockwave-flash"/>
</item>
</channel>
Run Code Online (Sandbox Code Playgroud)
当我遍历项目时,我可以通过SyndicationItem的公共属性获取标题和链接.
我似乎无法弄清楚如何获取机箱标签的属性或媒体标签的值.我试过用
SyndicationItem.ElementExtensions.ReadElementExtensions<string>("player", "http://search.yahoo.com/mrss/")
Run Code Online (Sandbox Code Playgroud)
对这两种方面有任何帮助吗?
我正在尝试将RSS提要的内容提取到可以在代码中操作的对象中.看起来.NET 3.5中的SyndicationFeed和SyndicationItem类将完成我的需要,除了一件事.每次我尝试使用SyndicationFeed类读取RSS提要的内容时,每个SyndicationItem的.Content元素都为null.
我通过FeedValidator运行我的Feed,并尝试使用来自其他几个来源的Feed,但无济于事.
XmlReader xr = XmlReader.Create("http://shortordercode.com/feed/");
SyndicationFeed feed = SyndicationFeed.Load(xr);
foreach (SyndicationItem item in feed.Items)
{
Console.WriteLine(item.Title.Text);
Console.WriteLine(item.Content.ToString());
}
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
我怀疑我可能只是在某个地方错过了一个步骤,但我似乎无法找到关于如何使用这些类消费RSS提要的好教程.
编辑:感谢SLaks我已经发现问题是WordPress使用内容标签.这似乎不是WP Atom提要的问题所以我现在将其作为解决方案.谢谢SLaks!
嗨,我正在尝试从Feed项中读取内容为字符串.
SyndicationFeed feed = SyndicationFeed.Load(feedReader);
SydicationContent itemContent = feed.Items.ToList<SyndicationItem>()[0].Content;
string retrivedContent = itemContent .......???
Run Code Online (Sandbox Code Playgroud)
如何从itemContent中读取文本?
该文档显示了如何创建TextSyndicationContent
TextSyndicationContent textContent = new TextSyndicationContent("Some text content");
SyndicationItem item = new SyndicationItem("Item Title", textContent, new Uri("server/items";), "ItemID", DateTime.Now);
Run Code Online (Sandbox Code Playgroud)
有什么方法可以扭转这个
谢谢
如何使用C#和.NET 4创建Atom条目?
我需要使用这种结构创建一个条目:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:f="XXX:aaa">
<title>title1</title>
<summary>summary1</summary>
</entry>
Run Code Online (Sandbox Code Playgroud)
我尝试使用SyndicationItem类执行此操作,但条目包含的信息超出了我的需要:
SyndicationItem atom = new SyndicationItem();
atom.Title = new TextSyndicationContent("test1", TextSyndicationContentKind.Plaintext);
atom.Summary = new TextSyndicationContent("summary1");
atom.AttributeExtensions.Add(new XmlQualifiedName("f", "http://www.w3.org/2000/xmlns/"), "XXX:aaa");
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineOnAttributes = true;
StringBuilder sb = new StringBuilder();
XmlWriter xml = XmlWriter.Create(sb,settings);
atom.SaveAsAtom10(xml);
xml.Close();
Console.WriteLine(sb.ToString());
Run Code Online (Sandbox Code Playgroud)
结果是:
<entry xmlns:f="XXX:aaa" xmlns="http://www.w3.org/2005/Atom">
<id>uuid:34381971-9feb-4444-9e6a-3fbc412ac6d2;id=1</id>
<title type="text">title1</title>
<summary type="text">summary1</summary>
<updated>2010-10-29T14:02:48Z</updated>
</entry>
Run Code Online (Sandbox Code Playgroud)
如何在没有的情况下创建原子入口对象,并输入="*"以使其看起来完全是我想要的?
你能帮我简化代码吗?
谢谢!
我正在使用.NET的SyndicationFeed来创建RSS和ATOM提要.不幸的是,我需要在描述元素(SyndicationItem的Content属性)中使用HTML内容,格式化程序会自动对HTML进行编码,但我宁愿将整个描述元素包装在CDATA中,而不对HTML进行编码.
我的(简单)代码:
var feed = new SyndicationFeed("Title", "Description",
new Uri("http://someuri.com"));
var items = new List<SyndicationItem>();
var item = new SyndicationItem("Item Title", (string)null,
new Uri("http://someitemuri.com"));
item.Content = SyndicationContent.CreateHtmlContent("<b>Item Content</b>");
items.Add(item);
feed.Items = items;
Run Code Online (Sandbox Code Playgroud)
有人知道如何使用SyndicationFeed做到这一点吗?我的最后一招是"手动"为feed创建XML,但我宁愿使用内置的SyndicationFeed.