module Hpricot::Traverse

def traverse_element(*names, &block) # :yields: element

:yields: element

{emptyelem <{http://www.w3.org/1999/xhtml}meta name="author" content="Who am I?">}
{emptyelem <{http://www.w3.org/1999/xhtml}meta name="robots" content="index,nofollow">}
# =>
t.traverse_element("{http://www.w3.org/1999/xhtml}meta") {|e| p e}
End




t = Hpricot(<<'End')

Universal names are specified as follows.

{emptyelem }
{emptyelem }
{elem
{elem {emptyelem } } {emptyelem } }
# =>
t.traverse_element("a", "c") {|e| p e}
t = Hpricot('')

A nested element is yielded in depth first order as follows.

If non-empty _names_ are given, it should be list of universal names.
If _names_ are empty, it yields all elements.

It yields elements in depth first order.
+traverse_element+ traverses elements in the tree.
def traverse_element(*names, &block) # :yields: element
  if names.empty?
    traverse_all_element(&block)
  else
    name_set = {}
    names.each {|n| name_set[n] = true }
    traverse_some_element(name_set, &block)
  end
  nil
end