cbourne
December 12, 2007, 12:59am
1
Hi,
I would like to process an XML file using REXML and recurse down through
some sub elements, e.g. the “group” and “cond” elements in the following
XML:
Test Rule
This is a test rule
2
However, I need to produce output that maintains the hierarchy so it can
be displayed as a nested list such as:-
Rule Name - Test Rule
Rule Description - Test Rule
group operator is all - condition name is condition 1
group operator is not - condition name is condition 2
group operator is not - condition name is condition 3
I can’t seem to find any examples of doing this, would somebody be so
kind as to provide me with an example of how I could do this?
Regards,
Carl
cbourne
December 12, 2007, 3:51pm
2
cbourne
December 12, 2007, 5:18pm
3
Gavin K. wrote:
Answer here:
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/5a948a058d3fac18
Thanks for this Gavin, however the link to this seems to be broken.
Please could you confirm it.
Best Regards,
Carl
cbourne
December 12, 2007, 5:36pm
4
Carl B. wrote:
Gavin K. wrote:
Answer here:
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/5a948a058d3fac18
Thanks for this Gavin, however the link to this seems to be broken.
Please could you confirm it.
Best Regards,
Carl
Thanks Gavin,
Seems to work OK now - will give it a try. Thanks again!
Carl
cbourne
December 12, 2007, 6:54pm
5
On Dec 11, 4:59 pm, Carl B. [email protected] wrote:
I would like to process an XML file using REXML and recurse down through
some sub elements, e.g. the “group” and “cond” elements in the following
XML:
[snip]
However, I need to produce output that maintains the hierarchy so it can
be displayed as a nested list such as:-
def show_element( element, level=0 )
print " "*level
do something with the element here
Depth-first recursion
element.children.each{ |child|
show_element( child, level+1 )
}
end
cbourne
December 12, 2007, 5:30pm
6
Carl B. wrote:
Gavin K. wrote:
Answer here:
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/5a948a058d3fac18
Thanks for this Gavin, however the link to this seems to be broken.
Please could you confirm it.
It works for me. If it’s not for you, you can also go to:
http://groups.google.com/group/comp.lang.ruby
and find the message titled “Recursing XML data using REXML”.