Recently, the problem of cleaning up the browser compatibility, the real head, with the help of predecessors, or a little progress, the following post some code, I think will be more useful
Copy Code code as follows:
var isie =????;
Global variables to determine whether IE, self-improvement
New Dom Method
function Parsexml (ST) {
if (Isie) {
var result = new ActiveXObject ("Microsoft". XMLDOM ");
Result.loadxml (ST);
} else {
var parser = new Domparser ();
var result = parser.parsefromstring (St, "Text/xml");
}
return result;
}
if (! Isie) {
var ex;
Defining node XML attributes
XMLDOCUMENT.PROTOTYPE.__PROTO__.__DEFINEGETTER__ ("XML", function () {
try {
Return to New XMLSerializer (). serializetostring (this);
catch (ex) {
var d = document.createelement ("div");
D.appendchild (this. CloneNode (true));
return d.innerhtml;
}
});
ELEMENT.PROTOTYPE.__PROTO__.__DEFINEGETTER__ ("XML", function () {
try {
Return to New XMLSerializer (). serializetostring (this);
catch (ex) {
var d = document.createelement ("div");
D.appendchild (this. CloneNode (true));
return d.innerhtml;
}
});
Define node Text property
xmldocument.prototype.__proto__.__definegetter__ ("Text", function () {
return this. firstchild.textcontent
});
element.prototype.__proto__.__definegetter__ ("Text", function () {
return this. textcontent
});
Define selectSingleNode, SelectNodes methods
XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function (XPath) {
var x = this. selectnodes (XPath)
if (! x | | X.length < 1) return null;
return x[0];
}
XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function (XPath) {
var xpe = new Xpathevaluator ();
var nsresolver = Xpe.creatensresolver (this. ownerdocument = null?
this. Documentelement:this. ownerdocument.documentelement);
var result = Xpe.evaluate (XPath, this, nsresolver, 0, NULL);
var found = [];
var res;
while (res = Result.iteratenext ())
Found.push (RES);
return found;
}
}