<?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>a work on process &#187; namespaces</title>
	<atom:link href="http://jystewart.net/process/tag/namespaces/feed/" rel="self" type="application/rss+xml" />
	<link>http://jystewart.net/process</link>
	<description>notes from another web developer</description>
	<lastBuildDate>Sat, 21 Aug 2010 13:09:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Namespaces, attributes and content in rxml</title>
		<link>http://jystewart.net/process/2006/08/namespaces-attributes-and-content-in-rxml/</link>
		<comments>http://jystewart.net/process/2006/08/namespaces-attributes-and-content-in-rxml/#comments</comments>
		<pubDate>Tue, 22 Aug 2006 09:03:07 +0000</pubDate>
		<dc:creator>James Stewart</dc:creator>
				<category><![CDATA[XML]]></category>
		<category><![CDATA[builder]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://jystewart.net/process/archives/2006/08/namespaces-attributes-and-content-in-rxml/</guid>
		<description><![CDATA[Rails&#8217; RXML templates (powered by Builder) are a great way to generate various different types of XML output from your application, but the documentation could be lacking. I&#8217;ve been working with namespaced content for a while but I&#8217;ve spent quite a while today trying to work out how to add an element in an explicit <a href="http://jystewart.net/process/2006/08/namespaces-attributes-and-content-in-rxml/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Rails&#8217; RXML templates (powered by <a href="http://builder.rubyforge.org/">Builder</a>) are a great way to generate various different types of XML output from your application, but the documentation could be lacking. I&#8217;ve been working with namespaced content for a while but I&#8217;ve spent quite a while today trying to work out how to add an element in an explicit namespace, with attributes and text content.</p>
<p>To create an &#8216;id&#8217; element is straightforward:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xml.<span style="color:#9900CC;">id</span> <span style="color:#996600;">'my-id-here'</span></pre></div></div>

<p>and then to put that tag in the &#8216;foo&#8217; namespace you need:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xml.<span style="color:#9900CC;">foo</span> <span style="color:#ff3333; font-weight:bold;">:id</span>, <span style="color:#996600;">'my-id-here'</span></pre></div></div>

<p>To create children of that element (say xhtml content in an atom feed) you need:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xml.<span style="color:#9900CC;">content</span> <span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'xhtml'</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
  xml.<span style="color:#9900CC;">xhtml</span> <span style="color:#ff3333; font-weight:bold;">:div</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    xml.<span style="color:#CC0066; font-weight:bold;">p</span> entry.<span style="color:#9900CC;">excerpt</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And the final piece of the puzzle, and the end to that particular bout of frustration is the <a href="http://builder.rubyforge.org/classes/Builder/XmlBase.html#M000008">text!</a> method. To use my exact example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xml.<span style="color:#9900CC;">georss</span> <span style="color:#ff3333; font-weight:bold;">:point</span>, <span style="color:#ff3333; font-weight:bold;">:featuretypetag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'wifi'</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
  xml.<span style="color:#9900CC;">text</span>! entry.<span style="color:#9900CC;">latitude</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">' '</span> <span style="color:#006600; font-weight:bold;">+</span> entry.<span style="color:#9900CC;">longitude</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jystewart.net/process/2006/08/namespaces-attributes-and-content-in-rxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
