Self referential xml using builder

Hi listers,

I’m trying to build an xml doc using Builder, but I’m having trouble
getting it to draw a tree structure from a self-referential table.
Here’s what I’m after:

---- object structure ----
node (name => root)

  • node (name => child 1)
  • node (name => child 2)
    • node (name => child 2.1)
    • node (name => child 2.2)

– should become –

Basically, I’m struggling to contain the childnodes within their parents
(getting a list of nodes is easy) - the structure is important, and
needs to be maintained for the parser that is working with this sucker.
I’m trying to keep this DRY, but currently am stuck on something like
this in the rxml template (which works but is obviously is limited to 2
levels deep):

node.children.each do |n|
xml.node(:name =>
n.children.each do |c|
xml.node(:name =>

Any ideas of how to do this cleanly in the template? Or do I need to
bust out some helper methods to get through this?

its a little expensive [correct me if Im wrong but I don’t think ruby
supports tail-recursion], but you might have to consider recursion esp
if you have unknown number of subnodes of subnodes, etc.

yea a helper would be in order to sort that out…