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!

Searching an xml document

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
I have a search script that searches my XML document but it is really slow / hangs does anybody know a better way of doing it?

Here is the script:

// Load XML file
mydata = new XML();
mydata.load("data.xml");
datalist = new Array();
function myOnLoad () {
datalist = mydata.firstChild.childNodes;
}
mydata.onLoad = myOnLoad;
// Search function
function search (string) {
Results = "";
count = 0;
string = string.toLowerCase();
if (string == "") {
Results = "Please enter a search term";
} else {
for (var i = 0; i<datalist.length; i++) {
no = i+1;
thing = datalist.firstChild.nodeValue.toLowerCase().toString();
function myreplace (rpl) {
while (thing.indexOf(rpl)>-1) {
pos = thing.indexOf(rpl);
thing = (thing.substring(0, pos) add thing.substring((pos+rpl.length), thing.length));
}
}
myreplace(&quot;,&quot;);
resultar = thing.split(&quot; &quot;);
for (var j = 0; j<resultar.length; j++) {
if (string == resultar[j]) {
count = count+1;
Results = Results add 'Result from page ' add no add ' : ' add '...' add resultar[j-3] add ' ' add resultar[j-2] add ' ' add resultar[j-1] add ' <font color=\&quot;#FF0000\&quot;><b>' add resultar[j] add '</b></font> ' add resultar[j+1] add ' ' add resultar[j+2] add ' ' add resultar[j+3] add '...<br><br>';
}
}
}
if (count == 0) {
Results = &quot;No matching results found&quot;;
} else {
Results = Results add '<br><br>' add count add ' results found';
}
}
gotoAndStop (2);
}

Here is the file :
Please help

From Big Dave
 
If anybody has any idea at all, I would like to hear it!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top