//http://www.activewidgets.com/javascript.forum.9267.5/question-on-reusing-code-of.html
if (window.XPathEvaluator) { 

  var xpath = new XPathEvaluator(); 

  if (!Element.prototype.selectSingleNode) { 
    Element.prototype.selectSingleNode = function (path) { 
      return xpath.evaluate(path, this, this.ownerDocument._ns, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; 
    }; 
  } 
   
  if (!Element.prototype.selectNodes) { 
    Element.prototype.selectNodes = function (path) { 
      var result = xpath.evaluate(path, this, this.ownerDocument._ns, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 
      var i, nodes = []; 
   
      for (i=0; i<result.snapshotLength; i++) { 
        nodes[i] = result.snapshotItem(i); 
      }; 
   
      return nodes; 
    }; 
  } 
   
  if (!Document.prototype.selectSingleNode) { 
    Document.prototype.selectSingleNode = function (path) { 
      return xpath.evaluate(path, this, this._ns, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; 
    }; 
  } 
   
  if (!Document.prototype.selectNodes) { 
    Document.prototype.selectNodes = function (path) { 
      var result = xpath.evaluate(path, this, this._ns, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 
      var i, nodes = []; 

      for (i=0; i<result.snapshotLength; i++) { 
        nodes[i] = result.snapshotItem(i); 
      }; 
       
      return nodes; 
    }; 
  } 

  Element.prototype.__defineGetter__('text', 
    function() { 
      var text = ''; 
        for (var i=0; i<this.childNodes.length; i++) { 
          text += this.childNodes[i].text; 
        }; 
        return text; 
    } 
  ); 
   
  Element.prototype.__lookupGetter__('text'); 

  Attr.prototype.__defineGetter__('text', function(){return this.nodeValue}); 
  Attr.prototype.__lookupGetter__('text'); 

  Text.prototype.__defineGetter__('text', function(){return this.nodeValue}); 
  Text.prototype.__lookupGetter__('text'); 
   
} 