标签: syndication-feed

使用SyndicationFeed读取SyndicationItem中的非标准元素

使用.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)

对这两种方面有任何帮助吗?

c# rss syndication-feed syndication-item

36
推荐指数
5
解决办法
3万
查看次数

是否有任何已定义的原子联合xml架构?

是否有任何已定义的原子联合xml架构?

RFC 4287在附录B中仅包含Relax NG紧凑模式.

xsd syndication syndication-feed atom-feed

17
推荐指数
1
解决办法
9189
查看次数

SyndicationItem.Content为Null

我正在尝试将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!

c# rss syndication-feed syndication-item

13
推荐指数
3
解决办法
6394
查看次数

我如何使用SyndicationFeed?

这可能看起来像一个愚蠢的问题,但我不能为我的生活弄清楚如何SyndicationFeed在c#中访问该类.我在MSDN上看到的每一个例子或者其他假设它已经被导入了,而我找到的没有一个例子给出了它所在位置的任何指示.

例如,我正在尝试运行以下内容:

XmlReader reader = XmlReader.Create(rss_url);
SyndicationFeed.Load(reader);
Run Code Online (Sandbox Code Playgroud)

但它失败了,因为SyndicationFeed在当前的上下文中不存在.那里有人知道我怎么能进去吗?

.net c# xml rss syndication-feed

13
推荐指数
1
解决办法
1万
查看次数

如何将SyndicationElementExtension添加到SyndicationItem

使用.NET System.ServiceModel.Syndication类...

我想向SyndicationItem添加一个新的SyndicationElementExtension,它将导出以下XML:

<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123" />
Run Code Online (Sandbox Code Playgroud)

有点像:

syndicationItem.ElementExtensions.Add(new SyndicationElementExtension("thumbnail", "http://video.search.yahoo.com/mrss", ?
Run Code Online (Sandbox Code Playgroud)

如何使用一些属性创建简单的SyndicationElementExtension?

.net c# syndication syndication-feed atom-feed

8
推荐指数
2
解决办法
7725
查看次数

Rss20FeedFormatter忽略SyndicationItem.Summary的TextSyndicationContent类型

在WCF项目中使用Rss20FeedFormatter类时,我试图用一个<![CDATA[ ]]>部分包装我的描述元素的内容.我发现无论我做了什么,描述元素的HTML内容总是被编码,并且从未添加CDATA部分.在深入研究Rss20FeedFormatter的源代码之后,我发现在构建Summary节点时,它基本上创建了一个新的TextSyndicationContent实例,该实例消除了之前指定的任何设置(我认为).

我的守则

public class CDataSyndicationContent : TextSyndicationContent
{
    public CDataSyndicationContent(TextSyndicationContent content)
        : base(content)
    {
    }

    protected override void WriteContentsTo(System.Xml.XmlWriter writer)
    {
        writer.WriteCData(Text);
    }
}
Run Code Online (Sandbox Code Playgroud)

...(以下代码应使用CDATA部分包装摘要)

SyndicationItem item = new SyndicationItem();
item.Title = new TextSyndicationContent(name);
item.Summary = new CDataSyndicationContent(
                   new TextSyndicationContent(
                         "<div>This is a test</div>", 
                         TextSyndicationContentKind.Html));
Run Code Online (Sandbox Code Playgroud)

Rss20FeedFormatter代码 (AFAIK,上面的代码因为这个逻辑不起作用)

...
else if (reader.IsStartElement("description", ""))
   result.Summary = new TextSyndicationContent(reader.ReadElementString());
...
Run Code Online (Sandbox Code Playgroud)

作为一种解决方法,我使用RSS20FeedFormatter来构建RSS,然后手动修补RSS.例如:

        StringBuilder buffer = new StringBuilder();
        XmlTextWriter writer = new XmlTextWriter(new StringWriter(buffer));
        feedFormatter.WriteTo(writer ); // feedFormatter = RSS20FeedFormatter …
Run Code Online (Sandbox Code Playgroud)

rss wcf syndication-feed

8
推荐指数
1
解决办法
1903
查看次数

是否可以使用PHP在RSS源中使用身份验证?

我正在尝试为Intranet文档管理系统开发一个feed,以便可以向员工通知新文档.我实际上已完成编码,但无法对用户进行身份验证.

此外,我没有成功地将新闻阅读器添加到新闻阅读器,但可以使用firefox Live Bookmark.

有任何想法吗

更新:

由于我无法解释得很好,我将具体到希望它能在OutLook RSS Feeds中工作.

谢谢

php feeds syndication-feed

7
推荐指数
1
解决办法
7044
查看次数

SyndicationFeed类不处理RSS版本0.91

.NET中的SyndicationFeed类似乎只支持RSS 2.0版.我如何支持RSS版本0.91?

syndication-feed

7
推荐指数
1
解决办法
941
查看次数

将命名空间添加到SyndicationFeed而不是单个元素?

我有一个这样的课:

public static class MyFeedExtensions
{
    private readonly static XNamespace _namespace = XNamespace.Get(@"http://mynamespace");

    public static XElement MyElement(string value)
    {
        return new XElement(_namespace + "MyElement", value);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用它来生成带有自定义扩展的Atom Feed:

var feed = new SyndicationFeed();
feed.ElementExtensions.Add(MyFeedExtensions.MyElement("Testing!"));
Run Code Online (Sandbox Code Playgroud)

这很好,除了feed将我的命名空间添加到元素:

<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Hello World!</title>
  <id>00000000-0000-0000-0000-000000000000</id>
  <updated>2011-03-01T01:00:53Z</updated>
  <MyElement xmlns="http://mynamespace">Testing!</MyElement>
</feed>
Run Code Online (Sandbox Code Playgroud)

有没有办法用feed注册命名空间,以获得这样的输出?

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:my="http://mynamespace">
  <title type="text">Hello World!</title>
  <id>00000000-0000-0000-0000-000000000000</id>
  <updated>2011-03-01T01:00:53Z</updated>
  <my:MyElement>Testing!</my:MyElement>
</feed>
Run Code Online (Sandbox Code Playgroud)

理想情况下,当我使用带有ElementExtensions的SyndicationItems时,我也希望这也能工作,因为feed应该知道所有各种命名空间.

(编辑:这纯粹是为了减少XML的大小并使其更容易为人类阅读)

.net syndication-feed atom-feed

7
推荐指数
1
解决办法
2353
查看次数

解析RSS提要最近抛出了文档类型定义(DTD)错误

这是最近开始困扰我的RSS提要解析器的错误.今天早上我的四个RSS源开始抛出此异常:

For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.

以前的代码工作正常,但我相信这四个特定的rss feed已经发生了变化,导致了这个问题.使用DTD时使用DTD的东西,或者某种类型的架构更改,而我的SyndicationFeed无法解析.

所以我将代码更改为

string url = RssFeed.AbsoluteUri;
XmlReaderSettings st = new XmlReaderSettings();

st.DtdProcessing = DtdProcessing.Parse;
st.ValidationType = ValidationType.DTD;

XmlReader reader = XmlReader.Create(url,st);

SyndicationFeed feed = SyndicationFeed.Load(reader);

reader.Close();
Run Code Online (Sandbox Code Playgroud)

然后我开始收到这个错误:

The 'html' element is not declared.System.Xml.XmlValidatingReaderImpl.ValidationEventHandling.System.Xml.IValidationEventHandling.SendEvent(Exception exception, XmlSeverityType severity) at System.Xml.Schema.BaseValidator.SendValidationEvent(String code, String arg) at System.Xml.Schema.DtdValidator.ProcessElement() at System.Xml.Schema.DtdValidator.ValidateElement() at System.Xml.Schema.DtdValidator.Validate() …

c# xml rss parsing syndication-feed

5
推荐指数
1
解决办法
2571
查看次数

标签 统计

syndication-feed ×10

c# ×5

rss ×5

.net ×3

atom-feed ×3

syndication ×2

syndication-item ×2

xml ×2

feeds ×1

parsing ×1

php ×1

wcf ×1

xsd ×1