<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>armisael.silix.org &#187; xml</title>
	<atom:link href="http://armisael.silix.org/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://armisael.silix.org</link>
	<description>Armisael's scientific world</description>
	<lastBuildDate>Thu, 01 Apr 2010 10:49:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby on Rails: adding custom elements in generated xml</title>
		<link>http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/</link>
		<comments>http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 15:54:57 +0000</pubDate>
		<dc:creator>Armisael</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://armisael.silix.org/?p=50</guid>
		<description><![CDATA[If you create a scaffold for your rails project, it will create for you a lot of things; for example, a way to show your object in xml format. But what about adding custom elements to that xml?
I solved in this way:

class MyObject &#60; ActiveRecord::Base
  #[...]
  def to_xml&#40;options=&#123;&#125;&#41;
    cp = [...]]]></description>
			<content:encoded><![CDATA[<p>If you create a scaffold for your rails project, it will create for you a lot of things; for example, a way to show your object in xml format. But what about adding custom elements to that xml?</p>
<p>I solved in this way:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MyObject <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;">#[...]</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> to_xml<span style="color:#006600; font-weight:bold;">&#40;</span>options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    cp = attributes.<span style="color:#9900CC;">clone</span>
    cp<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;something&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;some value&quot;</span>
    cp<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;another thing&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">some_relation</span>.<span style="color:#9900CC;">length</span>
    cp.<span style="color:#9900CC;">to_xml</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
