Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Speedy XML parsing

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
I built this function to parse and render my XML:

Code:
stop ();
var mySort = new Array();
var pXML = new XML();
pXML.onLoad = readXML;
pXML.load("file.xml");
function chkDup (hts, qry) {
	for (var i = 0; i<mySort.length; i++) {
		if (mySort[i][1] == qry) {
			mySort[i] = [mySort[i][0]+hts, qry, mySort[i][2]];
			return true;
		}
	}
	return false;
}
function readXML () {
	if (pXML.loaded) {
		for (var x = 0; x<pXML.childNodes[2].childNodes[0].childNodes[1].childNodes[0].childNodes[1].childNodes.length; x++) {
			for (var y = 0; y<pXML.childNodes[2].childNodes[0].childNodes[1].childNodes[0].childNodes[1].childNodes[x].childNodes[2].childNodes.length; y++) {
				Query = new String(pXML.childNodes[2].childNodes[0].childNodes[1].childNodes[0].childNodes[1].childNodes[x].childNodes[2].childNodes[y].childNodes);
				Hits = parseFloat(pXML.childNodes[2].childNodes[0].childNodes[1].childNodes[0].childNodes[1].childNodes[x].childNodes[2].childNodes[y].attributes.Hits);
				Av = pXML.childNodes[2].childNodes[0].childNodes[1].childNodes[0].childNodes[1].childNodes[x].childNodes[2].childNodes[y].attributes.AvgRank;
				if (chkDup(Hits, Query) != true) {
					mySort[mySort.length] = [Hits, Query, Av];
				}
			}
		}
		renderXML();
	} else {
		readXML();
	}
}

function renderXML () {
	mySort.sort();
	var tt = mySort.length-11;
	i = 0;
	for (var p = mySort.length-1; p>tt; p--) {
		i++;
		_root[&quot;query&quot;+i] = mySort[p][1];
		_root[&quot;hits&quot;+i] = mySort[p][0];
		_root[&quot;av&quot;+i] = mySort[p][2];
	}
	_root.loadt._visible = 0;
}

It works fine but I'm wondering if there is a faster way (It may just be the length of the XML document!) to parse the XML Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top