views:

833

answers:

3

The default rails XML builder escapes all html so something like:

atom_feed do |feed|  
  @stories.each do |story|  
    feed.entry story do |entry|   
      entry.title story.title
      entry.content "<b>foo</b>"
    end  
  end  
end

will produce the text:

<b>foo</b>

instead of: foo

Is there any way to instruct the XML builder to not escape the XML?

+5  A: 

turns out you need to do

entry.content "<b>foo</b>", :type => "html"

althought wrapping it in a CDATA stops it working.

Shalmanese
A: 

Neither of those answers work and I can't find anything else about it online. The docs don't indicate how the stripping is occurring or how to avoid it. Anybody have any ideas how to solve this?

A: 

http://builder.rubyforge.org/classes/Builder/XmlMarkup.html

The special XML characters <, >, and & are converted to <, > and & automatically. Use the << operation to insert text without modification.