Problems parsing XML file with javascript (limit results)

krishparmard

New Member
I have the script listed at bottom that parse informations from XML file and run correctly. If I want to show a max limit results (for example 5), I'm not able to do it. I think "Slice" function is what I need. I have no problems to use the same function in a simple text array ("Mango, "Banana", "Kiwi", "Peach"). Any suggestions? Thanks in advance.\[code\]if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.open("GET","cd_catalog.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML; x=xmlDoc.getElementsByTagName("CD");function displayCDInfo(i){ artist=(x.getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue); title=(x.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); year=(x.getElementsByTagName("YEAR")[0].childNodes[0].nodeValue); country=(x.getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue); company=(x.getElementsByTagName("COMPANY")[0].childNodes[0].nodeValue); price=(x.getElementsByTagName("PRICE")[0].childNodes[0].nodeValue); txt="Artist: "+artist+"<br />Title: "+title+"<br />Year: "+year+"<br />Country: "+country+"<br />Company: "+company+"<br />Price: "+price ; document.getElementById("showCD").innerHTML=txt;}\[/code\]
 
Back
Top