Using XML parsing for such simple markup is a waste. If you want to speed up the use of indexOf and substrings .
http://jsperf.com/1f/2
I edited @Royi Namir jsperf and added my own version (aptly named "screw xml"). It runs 2 times faster than its optimized version of XML parsing.
Here is code that does not match the OP example from the question. The variable "xml" is just a string representing XML.
var find = ''; var start = -1; var end = -1; var skip1 = 0; var skip2 = ' avg="'.length; // for (i=0;i<lanes.length;i++) { find = 'num="' + lanes[i] + '"'; skip1 = find.length; end = -1; start = xml.indexOf(find, 0); while (start != -1) { start = start + skip1 + skip2; end = xml.indexOf("\"/>", start); htmlContents += GetLaneInfo(xml.substring(start, end)); start = xml.indexOf(find, end); } }
In fact, you probably do not want to use a version similar to the one above, because it depends on the format evenly formatted (see "skip2" variable / constant). But if you really want performance / speed to run like this, this is the fastest.
source share