Hello,
I’m having a great time building some rss/atom feeds and I’ve been
quite successful until I hit the html formatting line of the Atom feed.
Here’s an example:
xml.instruct! :xml, :version=>“1.0”, :encoding=>“UTF-8”
xml.feed “xml:lang” => “en-US”, “xmlns” =>
'Atom Syndication Format namespace ’ do
xml.title("flavor: #{@flavor} *title1: " + @feed.title)
xml.id(
“tag:#{request.host},#{Time.now.utc.year}:#{@feed.title}/#{@feed.title.downcase}”
)
xml.link('url: ’ + @ feed.guid) if @feed.guid
xml.author { xml.name “Author Name” }
@entities.each do |entity|
xml.entry do
xml.title('title: ' + entity.title )
xml.link("rel" => "alternate", "href" => url_for(url_for
:only_path => false, :controller => @this_controller, :action =>
@this_action, :id => entity.id))
xml.id(url_for(:only_path => false, :controller =>
@this_controller, :action => @this_action, :id => entity.id))
xml.updated(“#{Time.now.utc.year}”)
xml.content "type" => "html" do
xml.name entity.body #-->>tried this - doesn't work
xml.text! render(:partial => "shared/feed/entity", :entity =>
entity)–>>Tried this - doesn’t work
end
end
end
end
If I could just get the
xml.content “type” => “html” do
end
section to work I would be home free.
Help!
xml.content “type” => “html” do
end
section to work I would be home free.
- You should be using xhtml for the content type. HTML assumes html
escaped text. XHTML wants well formed HTML starting with a div tag:
- You can use the #<< method to add raw xml to the xml object.
Here’s how I do it in Mephisto:
http://svn.techno-weenie.net/projects/mephisto/trunk/app/views/feed/_article.rxml
(sanitize_feed_content is in here)
http://svn.techno-weenie.net/projects/mephisto/trunk/app/helpers/application_helper.rb
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Rick - thanks for all your help.
I’m not quite sure I fully understand this. The closest I’m coming to
getting this displayed correctly is w/ this:
xml.content “type” => “xhtml” do
xml.content( "<div
xmlns="http://www.w3.org/1999/xhtml\“>#{entity.body}</div>”)
end
This displays the info but does not render the html properly.
what am I missing?
Also, When I try this atom method in windows IE, it completely fails and
spits the output w/out any rendering at all.
lordy.
Rick O. wrote:
- You should be using xhtml for the content type. HTML assumes html
escaped text. XHTML wants well formed HTML starting with a div tag:
RFC 4287 - The Atom Syndication Format
Okay, just to be clear… I assumed from your code you want strongly
typed HTML, which is why I suggested the XHTML content type. In
Mephisto, I don’t run the content through tidy or anything and can’t
guarantee xhtml compliance, so I just use HTML for now. Use what you
like. I just wanted to highlight the difference between the two.
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Also when I try rendering this feed as rss in windows IE it doesn’t even
respond.
Double Lordy.
- You should be using xhtml for the content type. HTML assumes html
escaped text. XHTML wants well formed HTML starting with a div tag:
RFC 4287 - The Atom Syndication Format
Okay, just to be clear… I assumed from your code you want strongly
typed HTML, which is why I suggested the XHTML content type. In
Mephisto, I don’t run the content through tidy or anything and can’t
guarantee xhtml compliance, so I just use HTML for now. Use what you
like. I just wanted to highlight the difference between the two.
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Also - does anyone know if there are good functional tests to test the
validation of the rss and atom feed structures?
Thanks,
desperate
On 1/26/07, Clem R. [email protected] wrote:
Also - does anyone know if there are good functional tests to test the
validation of the rss and atom feed structures?
Look at how typo does it. I believe it calls the feed validator, or
checks for and uses the local feed validator lib if it exists.
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
Rick - I did try this:
xml.content “type” => “xhtml” do
xml << %{"
" + entity.body + “
” }
end
and it does render the html code properly but, for only one entry. In
other words, if I have 2 records in a database, only the first one is
getting displayed.
Weird. I’m close but missing something basic.
Thanks so much for your help.
On 1/26/07, clem_c_rock [email protected] wrote:
This displays the info but does not render the html properly.
what am I missing?
Also, When I try this atom method in windows IE, it completely fails and
spits the output w/out any rendering at all.
lordy.
Impossible to solve, this is, without an example of the result xml.
Well, on first glance, you didnt use << at all. sooo…
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
I also tried to render the xml.content section w/ a partial like this:
xml.content “type” => “html” do
xml.text! render(partial => “shared/feed/entity”, :entity => entity,
:xm => xml)
end
and the partial code would contain:
xm.entry ‘xml:base’ => home_url do
xm.title('title: ’ + entity.title )
xm.link(“rel” => “alternate”, “href” => url_for(url_for :only_path
=> false, :controller => @this_controller, :action => @this_action, :id
=> entity.id))
xm.id(url_for(:only_path => false, :controller => @this_controller,
:action => @this_action, :id => entity.id))
xm.updated("#{Time.now.utc.year}")
xm.author { xm.name “Author Name” }
xm << %{****#{entity.body}}
end
This still only prints out the first line.
Clem R. wrote:
Rick - I did try this:
xml.content “type” => “xhtml” do
xml << %{"
" + entity.body + “
” }
end
and it does render the html code properly but, for only one entry. In
other words, if I have 2 records in a database, only the first one is
getting displayed.
Weird. I’m close but missing something basic.
Thanks so much for your help.