Half-assed way of retrieving all document nodes.
This currently only works for documents, is not tested and most likely will leak memory due to being recursive.
This commit is contained in:
parent
52a4375278
commit
8fe71f298b
|
@ -49,6 +49,34 @@ module Oga
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a NodeSet containing *all* the nodes in the current document.
|
||||
# Nodes are inserted in the order they appear in the document.
|
||||
#
|
||||
# @return [Oga::XML::NodeSet]
|
||||
#
|
||||
def all_nodes
|
||||
return gather_child_nodes(self)
|
||||
end
|
||||
|
||||
##
|
||||
# Recursively retrieves all child nodes of `node` and returns them as a
|
||||
# node set.
|
||||
#
|
||||
# @param [Oga::XML::Document|Oga::XML::Node] node
|
||||
# @return [Oga::XML::NodeSet]
|
||||
#
|
||||
def gather_child_nodes(node)
|
||||
nodes = NodeSet.new
|
||||
|
||||
node.children.each do |child|
|
||||
nodes << child
|
||||
nodes += gather_child_nodes(child)
|
||||
end
|
||||
|
||||
return nodes
|
||||
end
|
||||
|
||||
##
|
||||
# Converts the document and its child nodes to XML.
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue