# File lib/scrubyt/utils/xpathutils.rb, line 35
    def self.generate_XPath(node, stopnode=nil, write_indices=false)
      path = []
      indices = []
      found = false
      while !node.nil? && node.class != Hpricot::Doc do
        if node == stopnode
          found = true
          break
        end
        path.push node.name
        indices.push find_index(node) if write_indices
        node = node.parent
      end
      #This condition ensures that if there is a stopnode, and we did not found it along the way,
      #we return nil (since the stopnode is not contained in the path at all)
      return nil if stopnode != nil && !found
      result = ""
      if write_indices
        path.reverse.zip(indices.reverse).each { |node,index| result += "#{node}[#{index}]/" }
      else
        path.reverse.each{ |node| result += "#{node}/" }
      end
      "/" + result.chop
    end