BigBadDave
Programmer
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(","
;
resultar = thing.split(" "
;
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=\"#FF0000\"><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 = "No matching results found";
} else {
Results = Results add '<br><br>' add count add ' results found';
}
}
gotoAndStop (2);
}
Here is the file :
Please help
From Big Dave
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(","

resultar = thing.split(" "

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=\"#FF0000\"><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 = "No matching results found";
} else {
Results = Results add '<br><br>' add count add ' results found';
}
}
gotoAndStop (2);
}
Here is the file :
Please help
From Big Dave