{"id":47,"date":"2003-10-08T07:19:00","date_gmt":"2003-10-08T07:19:00","guid":{"rendered":"http:\/\/jclark.org\/weblog\/WebDev\/Blosxom\/xhtmlbody.html"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-30T04:00:00","slug":"xhtmlbody","status":"publish","type":"post","link":"https:\/\/jclark.org\/weblog\/2003\/10\/08\/xhtmlbody\/","title":{"rendered":"Using xhtml:body in RSS feeds via Blosxom"},"content":{"rendered":"<p>As I mentioned <a href=\"http:\/\/jclark.org\/weblog\/WebDev\/Blogging\/nnw.html\">previously<\/a>, I&#8217;ve recently begun using the full version of <a href=\"http:\/\/ranchero.com\/netnewswire\/\">NetNewsWire<\/a>, which honors the use of xhtml:body within an <span class=\"caps\">RSS<\/span> feed.  When I upgraded my feed to <span class=\"caps\">RSS 2.0<\/span> a while ago, I decided to include a forshortend version of the story in the <span class=\"caps\">RSS <\/span>\n tag, and the full, xhtml content of the story within .  Since I had been using NetNewsWire Lite, I could only see the short description.<\/p>\n<p>When I loaded feed into NetNewsWire, I found to my horror that all of the xhtml tags were being escaped within my xhtml:body.  I looked at my <span class=\"caps\">RSS<\/span> flavour&#8217;s story template, and my html flavour&#8217;s story template.  Both use $body to include the body of a post.  But my html pages don&#8217;t have all of the tags escaped.<\/p>\n<p>It turns out that blosxom.cgi is the culprit&#8230; it includes logic to escape less-thans and ampersands within storys if the output mime type includes &#8216;xml&#8217;.  This isn&#8217;t exactly a bug&#8230; arbitrary xml (or html) tags within the larger <span class=\"caps\">RSS<\/span> xml document could cause the <span class=\"caps\">RSS<\/span> file not to be well-formed, and so to not parse with standard <span class=\"caps\">XML<\/span> tools.  However, since my content is all valid xhtml, and is being enclosed within the feed inside an xhtml:body, there&#8217;s no need for this escaping.<\/p>\n<p>I patched my blosxom.cgi in the manner I would expect the change to be made to the official blosxom.cgi&#8230; as a configurable option.  The changes are as follows.<\/p>\n<ol>\n<li>Add a new config variable<\/li>\n<li>Add it to the vars declaration<\/li>\n<li>Change the code to check this variable.<\/li>\n<\/ol>\n<p>In more detail:<\/p>\n<p>Step 1: In the &#8216;Configuration Variables&#8217; section at the top of the file, add a config var.<\/p>\n<pre><code> #set to 1 if RSS template wraps $body in &lt;body&gt;\n$rss_xhtml = 1;&lt;\/body&gt;<\/code><\/pre>\n<p>Step 2: Find the &#8216;use vars&#8217; section right below the configuration varibales.  Add <code>$rss_xhtml<\/code> to the list of variables between the !&#8217;s.<\/p>\n<p>Step 3: Update the code.  Look for this block of code (try searching for &#8216;xml&#8217;:<\/p>\n<pre><code>      if ($content_type =~ m{\\Wxml$}) {\n        # Escape &lt;, &gt;, and &amp;, and to produce valid RSS\n        my %escape = (&#039;&lt;&#039;=&gt;&#039;&lt;&#039;, &#039;&gt;&#039;=&gt;&#039;&gt;&#039;, &#039;&amp;&#039;=&gt;&#039;&amp;&#039;, &#039;&quot;&#039;=&gt;&#039;&quot;&#039;);\n        my $escape_re  = join &#039;|&#039; =&gt; keys %escape;\n        $title =~ s\/($escape_re)\/$escape{$1}\/g;\n        $body =~ s\/($escape_re)\/$escape{$1}\/g;\n      }\n<\/code><\/pre>\n<p>And change the first line to look like this:<\/p>\n<p><code><\/code><\/p>\n<pre>      if (!$rss_xhtml and $content_type =~ m{\\Wxml$}) {<\/pre>\n<p>I&#8217;m going to submit this to the list and see if Rael will incorporate it into blosxom.cgi.  <\/p>","protected":false},"excerpt":{"rendered":"<p>As I mentioned previously, I&#8217;ve recently begun using the full version of NetNewsWire, which honors the use of xhtml:body within an RSS feed. When I upgraded my feed to RSS 2.0 a while ago, I decided to include a forshortend version of the story in the RSS tag, and the full, xhtml content of the [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-blosxom"],"_links":{"self":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":0,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"wp:attachment":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}