git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / common / xpath.js
diff --git a/doc/webdeveloper/common/xpath.js b/doc/webdeveloper/common/xpath.js
new file mode 100644 (file)
index 0000000..0b515e3
--- /dev/null
@@ -0,0 +1,26 @@
+// Evaluates an XPath against a given node
+function webdeveloper_evaluateXPath(node, xPath)
+{
+    var result         = null;
+    var resultList     = new Array();
+    var xPathEvaluator = new XPathEvaluator();
+    var results        = null;
+
+    // If the node has an owner document
+    if(node.ownerDocument)
+    {
+        results = xPathEvaluator.evaluate(xPath, node, xPathEvaluator.createNSResolver(node.ownerDocument.documentElement), 0, null);
+    }
+    else
+    {
+        results = xPathEvaluator.evaluate(xPath, node, xPathEvaluator.createNSResolver(node.documentElement), 0, null);
+    }
+
+    // Loop through the results
+    while((result = results.iterateNext()) != null)
+    {
+        resultList.push(result);
+    }
+
+    return resultList;
+}
\ No newline at end of file