class Nokogiri::XML::Node

def ancestors

Get a list of ancestor Node for this Node
##
def ancestors
  return [] unless respond_to?(:parent)
  parents = [parent]
  while parents.last.respond_to?(:parent)
    parents << parents.last.parent
  end
  parents
end