那么我没有看到写出xml-stylesheet
处理指令给你写SyndicationFeed到相同的XmlWriter的任何问题。示例代码
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();
}
写道
<?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>
到控制台,你可以写任何目的地的的XmlWriter可以写入相同的方式。
啊,那简单得多。我知道肯定有更好的办法,但现在看来它很明显,现在它已经摆在我面前了。谢谢! – Matt