Rails xml-builder自定义命名空间删除空格

时间:2013-07-15 16:37:36

标签: ruby-on-rails xml-builder

我有一个Google商家中心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>

请注意,图片的网址位于下一行并缩进,不起作用。我需要的是:

<feed>
  <entry>
    <g:image_link>http://www.mysite.com/resources/images/pic.jpg</g:image_link>
  </entry>
</feed>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

为了帮助其他人解决此问题,我最终如何解决它是通过更改细节线

自:

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/