jump to navigation

Hyphenated XML tags in Builder October 13, 2008

Posted by John Dewey in ActiveRecord, Example, Rails, Ruby.
trackback

I typically use to_xml when building a shallow representation of my model in XML. It becomes hella difficult to maintain the format of my XML when nesting numerous levels deep. Sometimes you gotta use a Builder.

If you would like your tags to be hyphenated (like the to_xml default), here is a nice trick:

xml.__send__('hyphenated-tag-name'.to_sym) do
  xml.tag "data"
end
Advertisements

Comments»

1. reidmix - October 22, 2008

I like that trick 😉

2. John Dewey - October 22, 2008

As you should, it was your “tricky trick”! 🙂

3. S. Brent Faulkner - December 6, 2008

or just…

xml.tag! “hyphenated-tag-name”, “data”


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: