On Apr 11, 2008, at 6:33 PM, KH wrote:> I''m new to Ruby and new to FXRuby. How to dump a fxtreelist to an
XML?
Well... I guess you could just iterate over the tree nodes and recurse
down into the various branches, adding nodes to the DOM (the XML
document object). So something like:
require ''fox16''
require ''rexml/document''
...
def add_subtree_for(tree_item, node)
tree_item.each do |child|
e = Element.new(''node'')
e.add_text(child.text)
node.add_element(e)
end
end
def dump_as_xml(tree_list)
doc = REXML::Document.new
tree_list.each do |tree_item|
e = Element.new(''node'')
e.add_text(tree_item.text)
doc.root.add_element(e)
add_subtree_for(tree_item, e)
end
end
Note that this is completely untested code, that I''ve just made up on
the spot! I''m assuming you have some more specific format and end use
in mind. Regardless, this is probably the sort of pattern that you''ll
follow.
Hope this helps,
Lyle
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/fxruby-users/attachments/20080411/ab057a96/attachment.html