Mindon.IDEA

Air off, Mind on ~ / Javascript+Golang, Sci, Health… /

Javascript之Mozilla XML

BlogMS original blog key: 1000533343, blog id: airoff History stat: 浏览/评论:275/3 , 日期:2005年8月18日 17:30

var isMozilla = (true && document.implementation && document.implementation.createDocument);

if(isMozilla) {

isMozilla = true;

Element.prototype.defineGetter("text", function () {

return this.firstChild.nodeValue;

});

Element.prototype.defineGetter("xml", function () {

return (new XMLSerializer()).serializeToString(this);

});

// why these two getters don’t work? still wonderring…

Element.prototype.selectSingleNode = function(xPath) {

var xPath;

var xresult = this.ownerDocument.evaluate(xPath, this

, null

, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

if(xresult && xresult.snapshotLength > 0) {

return xresult.snapshotItem(0);

} else {

return null;

}

}

Element.prototype.selectNodes = function(xPath) {

var xPath;

var xresult = this.ownerDocument.evaluate(xPath, this

, null

, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

var nod = null, nods = [], k = 0;

while((nod=xresult.iterateNext())!=null) {

nods[k++] = nod;

}

return nods;

}

XMLDocument.prototype.selectSingleNode = function(xPath) {

var xPath;

var xresult = this.evaluate(xPath, this

, null

, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

if(xresult && xresult.snapshotLength > 0) {

return xresult.snapshotItem(0);

} else {

return null;

}

}

XMLDocument.prototype.selectNodes = function(xPath) {

var xPath;

var xresult = this.evaluate(xPath, this

, null

, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

var nod = null, nods = [], k = 0;

while((nod=xresult.iterateNext())!=null) {

nods[k++] = nod;

}

return nods;

}

}

Comments