↑
Main Page
XPath Support in Browsers
this.parseError.url = RegExp.$2;
this.parseError.line = parseInt(RegExp.$3);
this.parseError.linepos = parseInt(RegExp.$4);
this.parseError.srcText = RegExp.$5;
}
};
Document.prototype.loadXML = function (sXml) {
this.__initError__();
this.__changeReadyState__(1);
var oParser = new DOMParser();
var oXmlDom = oParser.parseFromString(sXml, “text/xml”);
while (this.firstChild) {
this.removeChild(this.firstChild);
}
for (var i=0; i < oXmlDom.childNodes.length; i++) {
var oNewNode = this.importNode(oXmlDom.childNodes[i], true);
this.appendChild(oNewNode);
}
this.__checkForErrors__();
this.__changeReadyState__(4);
};
Document.prototype.__load__ = Document.prototype.load;
Document.prototype.load = function (sURL) {
this.__initError__();
this.__changeReadyState__(1);
this.__load__(sURL);
};
Node.prototype.__defineGetter__(“xml”, function () {
var oSerializer = new XMLSerializer();
return oSerializer.serializeToString(this, “text/xml”);
});
}
XPath Support in Browsers
Because XML was being used for so many kinds of data, it became necessary to create a means to locate
data inside of XML code. The answer to this problem is XPath, which is a small language used specifi-
cally to locate a single node or multiple nodes that match a particular pattern. Although an in-depth dis-
cussion of XPath is beyond the scope of this book, a brief introduction is in order.
465
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 465
Free JavaScript Editor
Ajax Editor
©
→