【问题标题】:Generating iTunes XML nodes in RSS feed using Ruby/Rails使用 Ruby/Rails 在 RSS 提要中生成 iTunes XML 节点
【发布时间】:2015-06-30 00:30:38
【问题描述】:

问:如何使用 Ruby/Rails 生成特定于 iTunes 的 XML 节点?

尝试生成 iTunes XML 提要,例如(基于example):

xml.instruct! :xml, :version => "1.0" 
xml.rss(:version => "2.0") do
  xml.channel do
    xml.title "Your Blog Title"
    xml.description "A blog about software and chocolate"
    xml.link posts_url

    @posts.each do |post|
      xml.item do
        xml.title post.title
        xml.description "Temporary post description"
        xml.pubDate post.created_at.to_s(:rfc822)
        xml.link post_url(post)
        xml.guid post_url(post)
      end
    end
  end
end

很高兴地产生了类似的东西:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Your Blog Title</title>
    <description>A blog about software and chocolate</description>
    <link>https://pubweb-thedanielmay.c9.io/sermons</link>
    <item>
       ... omitted ...
    </item>
  </channel>
</rss>

但看起来我需要生成特定于 iTunes 的 XML 节点(例如按照 Working With iTunes

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> <-- *
  <channel>
    <title>Your Blog Title </title>
    ... omitted ...
    <itunes:subtitle>A program about everything</itunes:subtitle> <-- *
... etc ...

不确定如何生成 iTunes 特定节点,因为它们中有冒号。

标准 RSS 节点如下:

xml.item --> <item>

如何生成如下节点:

  • &lt;rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"&gt;
  • &lt;itunes:author&gt;

【问题讨论】:

    标签: ruby-on-rails xml rss itunes


    【解决方案1】:

    啊,根据 Ryan Bates 的出色 Railscasts RSS sample 的代码回答

    xml.rss "xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd", :version => "2.0"
    

    xml.itunes :author, author
    

    【讨论】:

      猜你喜欢
      • 2011-06-17
      • 2016-04-05
      • 2013-10-27
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多