if (window.XPathEvaluator) {
var xpath = new XPathEvaluator();
var element = Element.prototype;
var attr = Attr.prototype;
var doc = Document.prototype;
delete element.text;
delete attr.text;
element.selectNodes = function (path) {
var result = xpath.evaluate(path, this, this.ownerDocument._ns, 7, null);
var i, nodes = [];
for (i=0; i<result.snapshotLength; i++) {
nodes[i] = result.snapshotItem(i);
nodes[i].text = nodes[i].firstChild ? nodes[i].firstChild.nodeValue : "";
}
return nodes;
};
element.selectSingleNode = function (path) {
var node = xpath.evaluate(path, this, this.ownerDocument._ns, 9, null).singleNodeValue;
dump('element.selectSingleNode(path): ' + path + '\n');
if ( node != null ) node.text = node.firstChild ? node.firstChild.nodeValue : "";
return node;
};
doc.selectSingleNode = function (path) {
dump('doc.selectSingleNode(path): ' + path + '\n');
var node = xpath.evaluate(path, this, this._ns, 9, null).singleNodeValue;
if ( node != null ) node.text = node.firstChild ? node.firstChild.nodeValue : "";
return node;
};
doc.selectNodes = function (path) {
var result = xpath.evaluate(path, this, this._ns, 7, null);
var i, nodes = [];
for (i=0; i<result.snapshotLength; i++) {
nodes[i] = result.snapshotItem(i);
nodes[i].text = nodes[i].firstChild ? nodes[i].firstChild.nodeValue : "";
}
return nodes;
};
}
function selectNodes(doc,path,c){
var xpath =new XPathEvaluator();
var result =xpath.evaluate(path,doc.documentElement,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
var nodeList =new Array();
for(var i =0;i <result.snapshotLength;i++){
nodeList.add(result.snapshotItem(i));
}
return nodeList;
}
function selectSingleNode(doc,path,c){
path +='[1]';
var nodes =selectNodes(doc,path,c);
if (nodes.length !=0){
return nodes[0];
}
else {
return null;
}
}
w.XMLDocument.prototype.selectNodes =function(path){
return selectNodes(this,path,this);
}
w.XMLDocument.prototype.selectSingleNode =function(path){
return selectSingleNode(this,path,null);
}
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');
}
This topic is archived.