Rails xml-builder custom namespace removes empty space

I have a google XML XML shopping center that prints extra blank space inside each element and I cannot get rid of it

I simplified the script below to demonstrate what I need. Current script:

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 

Outputs:

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

Note that the image URL is on the next line and indented, which will not work. What I need:

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

How can I solve this problem?

+4
source share
1 answer

To help anyone else with this problem in the future, as I finally solved it by changing the line strings

From:

 xml.g :image_link do xml.text!("http://www.mysite.com/{product.picture}"); end 

To:

 xml.g :image_link, "http://www.mysite.com#{product.picture}" 

Thanks: http://codalicious.wordpress.com/2010/06/16/product-rss-feed-for-google-base/

+4
source

Source: https://habr.com/ru/post/1491483/


All Articles