4

a10 に加えて、フィードの rss(root) 要素に新しい名前空間を追加する必要があります。

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

RSS 2.0 にシリアル化された SyndicationFeed クラスを使用しており、XmlWriter を使用してフィードを出力しています。

var feed = new SyndicationFeed(
                    feedDefinition.Title,
                    feedDefinition.Description,
     .
     .
     .



using (var writer = XmlWriter.Create(context.HttpContext.Response.Output, settings))
        {
            rssFormatter.WriteTo(writer);
        }

SyndicationFeed に AttributeExtensions を追加しようとしましたが、新しい名前空間がルートではなくチャネル要素に追加されます。

ありがとうございました

4

1 に答える 1

4

残念ながら、フォーマッタは必要な方法で拡張できません。

中間のXmlDocumentを使用して、最終出力に書き込む前に変更することができます。

このコードは、最終的なxml出力のルート要素に名前空間を追加します。

var feed = new SyndicationFeed("foo", "bar", new Uri("http://www.example.com"));
var rssFeedFormatter = new Rss20FeedFormatter(feed);

// Create a new  XmlDocument in order to modify the root element
var xmlDoc = new XmlDocument();

// Write the RSS formatted feed directly into the xml doc
using(var xw = xmlDoc.CreateNavigator().AppendChild() )
{
    rssFeedFormatter.WriteTo(xw);
}

// modify the document as you want
xmlDoc.DocumentElement.SetAttribute("xmlns:example", "www.example.com");

// now create your writer and output to it:
var sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb))
{
    xmlDoc.WriteTo(writer);
}

Console.WriteLine(sb.ToString());
于 2013-01-18T17:46:02.250 に答える