我有一个 Google Merchant Center XML 脚本,它在每个元素中打印额外的空白,但我似乎无法摆脱它
我已经简化了下面的脚本来演示我所追求的。当前的
脚本:
xml.instruct!
xml.feed 'xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:g' => 'http://base.google.com/ns/1.0' do
@site.products.find(:all).each do |product|
xml.entry do
xml.g :image_link do xml.text!("http://www.mysite.com/{product.picture}"); end
end
end
end
输出:
<feed>
<entry>
<g:image_link>
http://www.mysite.com/resources/images/pic.jpg
</g:image_link>
</entry>
</feed>
请注意,图像的 url 位于下一行并缩进,这将不起作用。我需要的是:
<feed>
<entry>
<g:image_link>http://www.mysite.com/resources/images/pic.jpg</g:image_link>
</entry>
</feed>
请问我该如何解决?
最佳答案
为了在 future 帮助其他人解决这个问题,我最终是如何通过更改细节行来解决这个问题的
从:
xml.g :image_link do xml.text!("http://www.mysite.com/{product.picture}"); end
到:
xml.g :image_link, "http://www.mysite.com#{product.picture}"
感谢:http://codalicious.wordpress.com/2010/06/16/product-rss-feed-for-google-base/
关于ruby-on-rails - Rails xml-builder 自定义命名空间删除空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17659271/