topical media & game development
professional-ajax-04-XPath-IE-SelectNodesBooks.htm / htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Book XML Exercise</title>
<script type="text/javascript" src="zxml.js"></script>
<script type="text/javascript">
function init() {
var oXmlDom = zXmlDom.createDocument();
oXmlDom.onreadystatechange = function () {
if (oXmlDom.readyState == 4) {
if (oXmlDom.parseError.errorCode == 0) {
//Attempt to select all <author/> elements
var aAuthors = oXmlDom.documentElement.selectNodes("book/author");
//Check if the length is 0.
if (aAuthors.length > 0) {
//Alert the user that something was found.
alert(aAuthors.length + " <author/> elements found.");
}
} else {
//Error! Alert the user.
var str = "An error occurred!!\n" +
"Description: " + oXmlDom.parseError.reason + "\n" +
"File: " + oXmlDom.parseError.url + "\n" +
"Line: " + oXmlDom.parseError.line + "\n" +
"Line Position: " + oXmlDom.parseError.linepos + "\n" +
"Source Code: " + oXmlDom.parseError.srcText;
alert(str);
}
}
};
oXmlDom.load("NoNameSpaceBooks.xml");
}
</script>
</head>
<body onload="init()">
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.