用于 C# .NET SyndicateFeed 的 XSLT 到 XHTML

发布于 2024-11-27 13:20:43 字数 269 浏览 0 评论 0原文

我正在使用 .NET SyndicateFeed 类创建供使用的 RSS 提要,但我需要将 XSLT 样式表链接到生成的 XML,以设置 Web 浏览器结果的样式。我还没有找到一种简单的方法来做到这一点。

我最好的选择是在生成 feed 后自己将 标签插入到生成的 XML 中,还是有更优雅的解决方案?

预先感谢,我非常感谢您的帮助。除了我自己直接修改生成的 XML 之外,我还无法找出或找到更好的解决方案。

I am using the .NET SyndicationFeed class to create an RSS feed for consumption, but I need to link an XSLT style sheet to the resulting XML to style the results for web browsers. I haven't been able to find an easy way of doing this.

Is my best bet to insert the <?xml-stylesheet ... ?> tag into the resulting XML myself after the feed has been generated, or is there a more elegant solution?

Thanks in advance, I really appreciate the help. I haven't been able to figure out or find a better solution save for directly modifying the resulting XML myself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩虹直至黑白 2024-12-04 13:20:43

嗯,我没有看到将 xml-stylesheet 处理指令写入到您编写 SyndicateFeed 的同一个 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 可以写入。

Well I don't see any problems writing out the xml-stylesheet processing instruction to the same XmlWriter you write the SyndicationFeed to e.g. the sample code

    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();
    }

writes

<?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>

to the console and the same way you could write to any destination an XmlWriter can write to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文