いくつかのカスタム要素を含むカスタム RSS フィードをセットアップしています。カスタム属性を含むカスタム要素を追加する必要があります。
これまでのところ、次のようなフィードを設定しました。
var testItem = new SyndicationItem("title", "description", new Uri("http://myuri.com"));
customItem.ElementExtensions.Add("customElement", String.Empty, "fooBar");
「items」という名前のリストに testItem を追加してから、次のようにします。
var feed = new SyndicationFeed("TestFeed", "FeedContent", new Uri("http://myuri.com"), items);
これは、このようなものを生成します...
<rss>
<channel>
<title>TestFeed</title>
<link>http://myuri.com</link>
<description>FeedContent</description>
<item>
<link>http://myprovider.com/contentid=1234</link>
<title>title</title>
<description>description</description>
<customElement>fooBar</customElement>
</item>
</channel>
</rss>
では、カスタム要素を追加してから、この要素にカスタム属性を追加したい場合はどうすればよいでしょうか?
次のように新しい SyndicationItem を作成できます。
var customElement = new SyndicationItem();
そして、次のように属性を追加します。
customElement.AttributeExtensions.Add(new XmlQualifiedName("myAttribute", ""), "someValue");
customElement.AttributeExtensions.Add(new XmlQualifiedName("anotherAttribute"), "someOtherValue");
そして、それを testItem に追加して、RSS フィードの項目のリストに追加します。
testItem.ElementExtensions.Add(customElement);
コンパイラはそれを食べますが、実行時エラーが発生します。これは、新しい要素に名前がないためだと思います。
私はこれを行う別の方法を見つけることができません
フィードの XmlDoc を作成し、要素と属性の追加を開始します。
そうする必要があるのは奇妙に思えますし、何かを監督したに違いないと感じています..
何か案は?