2011-08-02 1 views
1

.NET SyndicationFeedクラスを使用して消費用のRSSフィードを作成していますが、XSLTスタイルシートを結果のXMLにリンクしてWebブラウザの結果をスタイルする必要があります。私はこれを行う簡単な方法を見つけることができませんでした。C#.NET SyndicationFeedのXSLTからXHTML

<?xml-stylesheet ... ?>タグをフィードの生成後に自分自身に挿入することをお勧めしますか、より洗練されたソリューションがありますか?

おかげさまで、本当に助けていただきありがとうございます。結果のXMLを直接修正するために、より良い解決策を見つけ出すことはできませんでした。

答えて

1

私はSyndicationFeedを書き込むのと同じXmlWriterにxml-stylesheet処理命令を書いても問題はありません。サンプルコード

SyndicationFeed feed = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://http://example.com/testfeed"), "TestFeedID", DateTime.Now); 
    SyndicationItem item = new SyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://example.com/ItemOne"), "TestItemID", DateTime.Now); 

    List<SyndicationItem> items = new List<SyndicationItem>(); 
    items.Add(item); 
    feed.Items = items; 

    using (XmlWriter xw = XmlWriter.Create(Console.Out, new XmlWriterSettings() { Indent = true })) 
    { 
     xw.WriteStartDocument(); 
     xw.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"sheet.xsl\""); 
     Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed); 
     atomFormatter.WriteTo(xw); 
     xw.Close(); 
    } 

は、コンソールとあなたがたXmlWriterに書き込みができる任意の宛先に書くことができます同じように

<?xml-stylesheet type="text/xsl" href="sheet.xsl"?> 
<feed xmlns="http://www.w3.org/2005/Atom"> 
    <title type="text">Test Feed</title> 
    <subtitle type="text">This is a test feed</subtitle> 
    <id>TestFeedID</id> 
    <updated>2011-08-02T13:19:12+02:00</updated> 
    <link rel="alternate" href="http://http//example.com/testfeed" /> 
    <entry> 
    <id>TestItemID</id> 
    <title type="text">Test Item</title> 
    <updated>2011-08-02T13:19:12+02:00</updated> 
    <link rel="alternate" href="http://example.com/ItemOne" /> 
    <content type="text">This is the content for Test Item</content> 
    </entry> 
</feed> 

を書き込みます。

+0

これはずっと簡単です。私はもっ​​と良い方法があったに違いないことを知っていましたが、これは私の前に置かれているので、これはかなり明白です。ありがとう! – Matt