Improving search through XML file I'm working on a function that extracts information from an XML document and compares to what the user has typed in. Can you suggest any ways in which I can improve it? The variables in the XML file are compared against txtSearch.

function checkXML() {
    var s = "";
    var albumPages = [];

    for (var i = 0; i &lt; xmlalbums.length; i++) {
        var xmlalbum = xmlalbums[i];
        var album_title = dataFromTag(xmlalbum, 'title');
        var artist = dataFromTag(xmlalbum, 'artist');
        var xmltracks = xmlalbum.getElementsByTagName('track');
        for (var t = 0; t &lt; xmltracks.length; t++) {
            var track = xmltracks[t];
            song_title = dataFromTag(track, 'title')
            albumPages[albumPages.length] = artist.toUpperCase() + ':' + album_title.toUpperCase() + ':' + song_title.toUpperCase();
        }
    }

    var resultList = '';
    var resultCount = [];

    for (var i = 0; i &lt; albumPages.length; i++) {
        var searchArtist = albumPages[i].substring(0, albumPages[i].indexOf(":"));
        var searchAlbum = albumPages[i].substring(albumPages[i].indexOf(":") + 1, albumPages[i].lastIndexOf(":"));
        var searchSong = albumPages[i].substring(albumPages[i].lastIndexOf(":") + 1, albumPages[i].length);
        if (searchArtist.indexOf(txtSearch) != -1 || searchAlbum.indexOf(txtSearch) != -1 || searchSong.indexOf(txtSearch) != -1) {
            resultList += "&lt;option&gt;" + searchSong + "&lt;/option&gt;"
            resultCount[resultCount.length] = i;
        }
    }

    if (resultList.length == 0) {
        s += "&lt;span style='font-size: 2em;color: #fff;font-family: Arial;'&gt;No result found!&lt;/span&gt;"
    }
    else if (resultList.length &gt; 0) {
        s += '&lt;select size="' + (resultCount.length + 1) + '" onclick="parent.col3(value);"&gt;';
        s += resultList;
        s += '&lt;/select&gt;';
    }
    else {
        s += "&lt;span style='font-size: 2em;color: #fff;font-family: Arial;'&gt;Awaiting search query...&lt;/span&gt;"
    }

    with(document.getElementById('col2').contentDocument) {
        open();
        write(s);
        close();
    }
}
A few general things from a quick scan:


declare all your variables at the top in one var statement rather than using it throughout the script
use somearray.push(x) rather than somearray[somearray.length]=x, as its shorter and means you don't have to look up the .length property every time in your loop
in general, avoid with; there are many reasons why e.g. http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
string concatenation is slow; instead of many += operators, create an array, use .push() as above to add strings to the array, then use .join('') to merge them together.


And yes, XPath would be a better approach to extract data from XML.