XML Paging in JavaScript

I was trying to develop a paging in XML with JavaScript and could write this code. It takes a XML file name as Input and gives five records on each page. No of records can be changed on each page. Check recordPerPage and max variable. I was working on this a long time back and thought before I delete this old code, better I publish it. It will take time for me to make it work for Internet Explorer as I am very new to XML with JavaScript. So, I am just publishing it as it is now. Making it work will not required to change everything but few methods that is not supported on IE. Conditional statement need to use for making it work on standard Web Browsers (Firefox, Chrome) and Internet Explorer. Code for JavaScript Paging in XML is working on Firefox and Chrome.

JavaScript Paging Example


<html>
<head>
<title> javascript paging xml </title>
<script>
if (window.XMLHttpRequest)
{
	xhttp = new XMLHttpRequest();
}
else
{
	xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","posts.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;
// Records on each page
var recordPerPage = 5;
var max = 5;
function nextpage()
{
	var np = max/1 + recordPerPage/1;
	path="/resultset/row[position()>=" + max + "and position() <" + np + "]/field[@name='post_title']";
	var nodes = xmlDoc.evaluate(path, xmlDoc, nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
	node.selectNodes(xpath);
	var result = nodes.iterateNext();
	var str='';
	while (result)
	{
	 str += result.textContent;
	 str += '<br />';
	 result = nodes.iterateNext();
	}
	document.getElementById('txtResult').innerHTML = str;
	max = np;
	return true;
}
function prevpage()
{
	max = max/1 - recordPerPage/1;
	var from = max/1 - recordPerPage/1;
	if (from <= 0) from=1;
	path="/resultset/row[position()>=" + from + "and position() <" + max + "]/field[@name='post_title']";
	var nodes = xmlDoc.evaluate(path, xmlDoc, nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
	var result = nodes.iterateNext();
	var str='';
	while (result)
	{
	 str += result.textContent;
	 str += '<br />';
	 result = nodes.iterateNext();
	}
	document.getElementById('txtResult').innerHTML = str;
	return true;
}
var nsResolver = document.createNSResolver(xmlDoc.ownerDocument==null?xmlDoc.documentElement:xmlDoc.ownerDocument.documentElement);
</script>
</head>
<body>
<div id="txtResult"></div>
<script type="text/javascript">
path="/resultset/row[position() <= 5]/field[@name='post_title']";
// code for IE
if (window.ActiveXObject)
{
	var nodes=xmlDoc.selectNodes(path);
	for (i=0;i<nodes.length;i++)
	{
	 document.write(nodes[i].childNodes[0].nodeValue);
	 document.write('<br />');
	}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
	rowCount = xmlDoc.evaluate('count('+ path +')', xmlDoc, null, XPathResult.ANY_TYPE,null);
	document.write('<h1>Number of Rows: ' + rowCount.numberValue + '</h1>');
	var nodes = xmlDoc.evaluate(path, xmlDoc, nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
	var result = nodes.iterateNext();
	var str = '';
	while (result)
	{
	 str += result.textContent; // childNodes[0].nodeValue
	 str += '<br />';
	 result = nodes.iterateNext();
	}
	document.getElementById('txtResult').innerHTML = str;
}
</script>
<hr>
<a href="#" onclick="javascript:prevpage();">Prev</a>
<a href="#" onclick="javascript:nextpage();">Next</a>
</body>
</html>

The XML file used in JavaScript paging demo can be found here. I see the example xml page (posts.xml) has a encoding error. That does not matter much as that is an example page and not useful for anyone. The page can be opened in Firefox.