<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_27268927.html</title>
</head>
<body>
<script type="text/javascript">
	if(window.XMLHttpRequest && navigator.appName.indexOf("Internet Explorer")<0) {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET","ShoeInventory.xml",false);
		xmlhttp.send();
		xmlDoc = xmlhttp.responseXML;
	}
	else {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.load("ShoeInventory.xml");
	}
	var a = [];
	var path = "//inventory/shoes/Type";
	if(document.evaluate) {
		iterator = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
		var currNode = iterator.iterateNext();
		while(currNode) {
			if(typeof a[currNode.textContent] == "undefined") {
				a[currNode.textContent] = 1;
			}
			else {
				a[currNode.textContent]++;
			}
			currNode = iterator.iterateNext();
		}
	}
	else {
		try {
		var nodes = xmlDoc.selectNodes(path);
		for(i=0;i<nodes.length;i++)  {
			if(typeof a[nodes[i].childNodes[0].nodeValue] == "undefined") {
				a[nodes[i].childNodes[0].nodeValue] = 1;
			}
			else {
				a[nodes[i].childNodes[0].nodeValue]++;
			}
		}
		}
		catch(e) { alert(e) }
	}
	
	for(var i in a) {	
		document.write(i + " Totals:" + a[i] + " <br / >");
	}
	
</script>
</body>
</html>