<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Generating custom XML for your rails app</title>
	<atom:link href="http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/feed/" rel="self" type="application/rss+xml" />
	<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/</link>
	<description>Dan Engle's Rails and Web Development Blog</description>
	<lastBuildDate>Mon, 10 May 2010 13:40:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Paul Hailes</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-408</link>
		<dc:creator>Paul Hailes</dc:creator>
		<pubDate>Sat, 24 Oct 2009 15:40:05 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-408</guid>
		<description>I can&#039;t believe how easy it just was to re-create a 2 page long php script which generated a xml file with a tiny bit of rails code.. and it&#039;s a lot cleaner and easier to read! Thanks for posting your feedback.
One thing that might help others is you can use standard # comments next to the code to put a example next of the output. (thought that&#039;s probably obvious to someone with more rails experience than me!)</description>
		<content:encoded><![CDATA[<p>I can&#8217;t believe how easy it just was to re-create a 2 page long php script which generated a xml file with a tiny bit of rails code.. and it&#8217;s a lot cleaner and easier to read! Thanks for posting your feedback.<br />
One thing that might help others is you can use standard # comments next to the code to put a example next of the output. (thought that&#8217;s probably obvious to someone with more rails experience than me!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-407</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Sun, 11 Oct 2009 03:05:21 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-407</guid>
		<description>You saved me a lot of time, thank you!</description>
		<content:encoded><![CDATA[<p>You saved me a lot of time, thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Carrig</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-406</link>
		<dc:creator>Jim Carrig</dc:creator>
		<pubDate>Fri, 02 Oct 2009 17:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-406</guid>
		<description>Another way is to override the default ActiveRecord to_xml method in post.rb.  This lets you easily use the same builder code in different contexts -- most importantly for singular and plural outputs.

For example, this takes care of both the posts.xml and posts/20.xml requests where the plural form uses

  format.xml { render :xml =&gt; @posts }
and the singular uses
  format.xml { render :xml =&gt; @post }

  def to_xml(options={})
    if options[:builder]
      build_xml(options[:builder])
    else
      xml = Builder::XmlMarkup.new
      xml.instruct!
      build_xml(xml)
    end
  end
  private
  def build_xml(xml)
      xml.tag!(&quot;created-at&quot;, created_at, :type =&gt; :datetime)
      xml.tag!(&quot;updated-at&quot;, updated_at, :type =&gt; :datetime)
      xml.title post.title
      xml.body post.body
      xml.published_at post.published_at
      xml.comments do
        post.comments.each do &#124;comment&#124;
          xml.comment do
            xml.body comment.body
          end
        end
      end
  end</description>
		<content:encoded><![CDATA[<p>Another way is to override the default ActiveRecord to_xml method in post.rb.  This lets you easily use the same builder code in different contexts &#8212; most importantly for singular and plural outputs.</p>
<p>For example, this takes care of both the posts.xml and posts/20.xml requests where the plural form uses</p>
<p>  format.xml { render <img src='http://danengle.us/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @posts }<br />
and the singular uses<br />
  format.xml { render <img src='http://danengle.us/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml =&gt; @post }</p>
<p>  def to_xml(options={})<br />
    if options[:builder]<br />
      build_xml(options[:builder])<br />
    else<br />
      xml = Builder::XmlMarkup.new<br />
      xml.instruct!<br />
      build_xml(xml)<br />
    end<br />
  end<br />
  private<br />
  def build_xml(xml)<br />
      xml.tag!(&#8220;created-at&#8221;, created_at, :type =&gt; :datetime)<br />
      xml.tag!(&#8220;updated-at&#8221;, updated_at, :type =&gt; :datetime)<br />
      xml.title post.title<br />
      xml.body post.body<br />
      xml.published_at post.published_at<br />
      xml.comments do<br />
        post.comments.each do |comment|<br />
          xml.comment do<br />
            xml.body comment.body<br />
          end<br />
        end<br />
      end<br />
  end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rails models are views? &#124; the evolving ultrasaurus</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-405</link>
		<dc:creator>rails models are views? &#124; the evolving ultrasaurus</dc:creator>
		<pubDate>Tue, 01 Sep 2009 03:07:17 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-405</guid>
		<description>[...] xml, this strange controller pattern is easily corrected by providing an xml view. The xml builder syntax is particularly readable, and it is easy to design your XML API [...]</description>
		<content:encoded><![CDATA[<p>[...] xml, this strange controller pattern is easily corrected by providing an xml view. The xml builder syntax is particularly readable, and it is easy to design your XML API [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Creating custom XML in Ruby on Rails : compiled thoughts</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-401</link>
		<dc:creator>Creating custom XML in Ruby on Rails : compiled thoughts</dc:creator>
		<pubDate>Sat, 11 Jul 2009 21:09:01 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-401</guid>
		<description>[...] a custom XML file for your model. I had a little trouble finding out how to do this on the web; this site and this one helped a little but could have been more specific. I&#8217;m going to go through this [...]</description>
		<content:encoded><![CDATA[<p>[...] a custom XML file for your model. I had a little trouble finding out how to do this on the web; this site and this one helped a little but could have been more specific. I&#8217;m going to go through this [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah Allen</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-353</link>
		<dc:creator>Sarah Allen</dc:creator>
		<pubDate>Sat, 20 Jun 2009 17:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-353</guid>
		<description>just curious... when was this XML builder syntax introduced into rails?</description>
		<content:encoded><![CDATA[<p>just curious&#8230; when was this XML builder syntax introduced into rails?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah Allen</title>
		<link>http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/comment-page-1/#comment-336</link>
		<dc:creator>Sarah Allen</dc:creator>
		<pubDate>Wed, 17 Jun 2009 23:14:24 +0000</pubDate>
		<guid isPermaLink="false">http://danengle.us/?p=83#comment-336</guid>
		<description>Awesome.  Exactly what I was looking for.  Thanks!</description>
		<content:encoded><![CDATA[<p>Awesome.  Exactly what I was looking for.  Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
