Looking at your code, it appears your xml file structure is something like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<client>
<sex>Male</sex>
</client>
<client>
<sex>Female</sex>
</client>
<client>
<sex>Male</sex>
</client>
</root>
I named the above test file testXML.xml in the demo below.
The demo below, based on your posted code but with a couple of "tweaks", works fine with the above xml data and outputs 33.33 as the percentage female.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function loadXMLDoc(dname){
if (window.XMLHttpRequest){
xhttp=new XMLHttpRequest();
} else {
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
xml=loadXMLDoc("testXML.xml");
function displaymember(){
var oClients = xml.getElementsByTagName("client");
var m = 0;
var f = 0;
for(i=0;i < oClients.length;i++) {
sex=(oClients[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue);
if (sex=="Male"){
m++;
} else {
f++;
}
}
document.getElementById("fixed").innerHTML = (f/ oClients.length * 100).toFixed(2);
}
window.onload=displaymember;
</script>
</head>
<body>
<div id="fixed"></div>
</body>
</html>