Here is a better patch which does not acces the text property/attribute of nodes but implements getter methods for the text property:

This is a diff against QxXmlExtras.js in cvs renderer branch.


Dietrich Streifert schrieb:

Hello List!


if someone needs this: Gecko/Mozilla has no implementation of the simple to handle xpath node selection methods selectNodes and selectSingleNode (which are InternetExplorerer proprietary) for Element and Document object. Here is the Implementation built as patch for QxXmlExtras.


A little tutorial for the usage is:


selectNodes: http://www.webreference.com/js/tips/020309.html
selectSingleNode: http://www.webreference.com/js/tips/020310.html

--

Mit freundlichen Grüßen
Dietrich Streifert
Visionet GmbH

--- source/script/binding/QxXmlExtras.js.orig   2005-11-29 09:12:47.100690000 
+0100
+++ source/script/binding/QxXmlExtras.js        2005-11-29 18:44:50.191349000 
+0100
@@ -105,3 +105,60 @@
 
   throw new Error("This browser does not support xml dom creation.");
 };
+
+// Implementation of selectNodes() and selectSingleNode()
+// for Gecko/Mozilla browsers
+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.text getter = function(){
+               var i, a=[], nodes = this.childNodes, length = nodes.length;
+               for (i=0; i<length; i++) {
+          a[i] = nodes[i].text
+        };
+               return a.join("");
+       };
+
+  Attr.prototype.text getter = function(){return this.nodeValue};
+  Text.prototype.text getter = function(){return this.nodeValue};
+}
+

Reply via email to