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
node.children.each do |n|
xml.node(:name => n.name)
n.children.each do |c|
xml.node(:name => c.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?