a work on process

Namespaces, attributes and content in rxml

You are reading a post by James Stewart entitled Namespaces, attributes and content in rxml. It was posted on 22 August 2006 at 4:03 am.

You can find more posts by returning to the index.

Filed under: XML
Tagged: , , ,

Rails’ 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’ve been working with namespaced content for a while but I’ve spent quite a while today trying to work out how to add an element in an explicit namespace, with attributes and text content.

To create an ‘id’ element is straightforward:

xml.id 'my-id-here'

and then to put that tag in the ‘foo’ namespace you need:

xml.foo :id, 'my-id-here'

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

xml.content :type => 'xhtml' do 
  xml.xhtml :div do
    xml.p entry.excerpt
  end
end

And the final piece of the puzzle, and the end to that particular bout of frustration is the text! method. To use my exact example:

xml.georss :point, :featuretypetag => 'wifi' do 
  xml.text! entry.latitude + ' ' + entry.longitude
end

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts

 

No Comments »

No comments yet.

TrackBack URI

Leave a comment

Login Method

OpenID

Anonymous