I am running some statistics against various URLS. I want to find the top level element with the most concentrated number of children. The method that I wo
# Non-recursive
class Nokogiri::XML::Node
def descendant_elements
xpath('.//*')
end
end
# Recursive 1
class Nokogiri::XML::Node
def descendant_elements
element_children.map{ |kid|
[kid, kid.descendant_elements]
}.flatten
end
end
# Recursive 2
class Nokogiri::XML::Node
def descendant_elements
kids = element_children.to_a
kids.concat(kids.map(&:descendant_elements)).flatten
end
end