SyndicationFeed变化空间$ P $从A10 PFIX到原子 [英] SyndicationFeed change namespace prefix from a10 to atom

查看:145
本文介绍了SyndicationFeed变化空间$ P $从A10 PFIX到原子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用System.ServiceModel.Syndication.SyndicationFeed创建一个RSS feed从我得到这样的:

I am using System.ServiceModel.Syndication.SyndicationFeed to create an rss feed from which I get this:

<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0"><channel>...</channel></rss>

这是所有工作顺顺当当的,除了当我验证我的供稿

验证器抱怨的A10命名空间preFIX,并建议我用原子代替。听起来很有道理..但我看不到改变的preFIX的简单方法。

The validator complains about the a10 namespace prefix and suggests that I use atom instead. That sounds reasonable.. except I can't see a straightforward way of changing the prefix.

在改变preFIX方式任何想法?

Any ideas on ways of changing the prefix?

推荐答案

要为你需要禁用SerializeExtensionsAsAtom进料格式的Atom扩展指定自定义名称:

To specify a custom name for the atom extensions you need to disable SerializeExtensionsAsAtom on the feed formatter:

var formatter = feed.GetRss20Formatter();
formatter.SerializeExtensionsAsAtom = false;

然后你需要添加命名空间

Then you need to add the namespace

XNamespace atom = "http://www.w3.org/2005/Atom";

feed.AttributeExtensions.Add(new XmlQualifiedName("atom", XNamespace.Xmlns.NamespaceName), atom.NamespaceName);

现在你可以开始使用扩展

And now you can start using the extensions

feed.ElementExtensions.Add(new XElement(atom + "link", new XAttribute("href", feedLink), new XAttribute("rel", "self"), new XAttribute("type", "application/rss+xml")));

最后写进响应流:

Finally write the feed to the response stream:

formatter.WriteTo(new XmlTextWriter(Response.Output));

这篇关于SyndicationFeed变化空间$ P $从A10 PFIX到原子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆