红宝石。我使用标准构建器来生成rss。我的构建器文件是:
xml.instruct! :xml, :version => "1.0"
xml.rss(:version => "2.0") {
xml.channel {
xml.title(@digest.name)
xml.description(@digest.name)
xml.link(url_for(:only_path => false))
for post in @posts
xml.item do
xml.title(post.title || '')
xml.description(post.summary)
xml.link(post.url)
xml.source(post.feed.name)
xml.guid(post.url)
xml.pubDate(post.pub_date.to_s(:rfc822))
end
end
}
}
要生成RSS Feed(require rss
),请使用下一代码:
xml.source(post.feed.name)
并获得:
<source>Cnn news</source>
但我想要这样的东西:
<source url="http://news.cnn.com">Cnn news</source>
如何将参数url
添加到xml源标记?
答案 0 :(得分:1)
我不确定你用的是什么库,但是如果你将哈希传递给构建器,它只会将其添加为节点的属性。
require 'builder'
=> true
x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
<inspect/>
=> #<IO:0x000000008822a0>
x.source("CNN News", "url" => "http://www.cnn.com")
<source url="http://www.cnn.com">CNN News</source>
=> #<IO:<STDOUT>>