javascript - retrieve data in xml, where the data is in xml -


i have following xml, in server

<root> <name> arun</name> <score> 20 </score> <name> varun</name> <score> 120 </score> </root>  

can maximum of score writing javascripts in xml , retrieve details html

here semi code try, made better it's starting point. please use firefox firebug plugin or chrome test it, press f12 open development tools , check out console errors

var httprequest; if (window.xmlhttprequest) { // mozilla, safari, ...     httprequest = new xmlhttprequest(); } else if (window.activexobject) { // ie 8 , older     httprequest = new activexobject("microsoft.xmlhttp"); }  httprequest.onreadystatechange = function(){   if (httprequest.readystate === 4 && httprequest.status === 200) {     // good, response received     // responsexml should xml file js document object     console.log(this.responsexml);     // score elements     var scores = this.responsexml.getelementsbytagname("score");     var arr=[]; //array containing score values     var tmpnum; // temporary store score value in here     for(var i=0;i<scores.length;i++){       //try convert score element innerhtml integer       tmpnum=parseint(scores[i].innerhtml.trim(),10);       // if tmpnum number store in scores array       if(!isnan(tmpnum)){         arr.push(tmpnum);       }     }     //sort arr (lowest first)     arr.sort();     // last element (is highest)     console.log("highest score:",arr[arr.length-1]);    } else {     // still not ready   } }; httprequest.open('get', "your url"); httprequest.send(); 

Comments