Moshambi
12-28-2009, 09:05 PM
Hello,
I have some code that I use to read an XML file:
function loadXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load("a.xml");
}
function searchXML()
{
var found = 0;
var headNodes = xmlDoc.getElementsByTagName("ac");
var srchArea = document.getElementById("txtArea").value;
var srchTerms = document.getElementById("txtFirst").value + document.getElementById("txtSecond").value;
for(var i = 0; i < headNodes.length; i++) //loop through nodes to look for matching area code
{
if(headNodes[i].getAttribute("val") == srchArea) //if its found then do this...
{
for(var x = 0; x < headNodes[i].childNodes.length; x++) //loop through child nodes of this block to see if there is a matching number
{
if(headNodes[i].childNodes[x].getAttribute("val") == srchTerms) //if there is a matching number then...
{
if(!document.getElementById("resultImg")) //check if image exists already and if it doesnt create one, otherwise just swap them
{
var result = document.getElementById("result")
var img = document.createElement("img");
img.src = "donotcall.bmp";
img.id = "resultImg";
result.appendChild(img);
}
else
{
document.getElementById("resultImg").src = "donotcall.bmp";
}
found = 1; //set found to true if the number matches
break; //break out of the loop when done
}
else
{
found = 0; //set found to false if there is not a match and then outside the loop do same image swap as above
}
}
}
}
if(found == 0)
{
if(!document.getElementById("resultImg"))
{
var result = document.getElementById("result")
var img = document.createElement("img");
img.src = "oktocall.bmp";
img.id = "resultImg";
result.appendChild(img);
}
else
{
document.getElementById("resultImg").src = "oktocall.bmp";
}
}
}
This code works great for small XML documents, but the one I just received that I need to search is like 26MB and that would take forever. I was wondering if there is a faster way to do this with either JS or if not then maybe PHP? The only thing I could tyhink of so far is to just separate the large file into multiple smaller files...
Hope someone can help, and thanks!
I have some code that I use to read an XML file:
function loadXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load("a.xml");
}
function searchXML()
{
var found = 0;
var headNodes = xmlDoc.getElementsByTagName("ac");
var srchArea = document.getElementById("txtArea").value;
var srchTerms = document.getElementById("txtFirst").value + document.getElementById("txtSecond").value;
for(var i = 0; i < headNodes.length; i++) //loop through nodes to look for matching area code
{
if(headNodes[i].getAttribute("val") == srchArea) //if its found then do this...
{
for(var x = 0; x < headNodes[i].childNodes.length; x++) //loop through child nodes of this block to see if there is a matching number
{
if(headNodes[i].childNodes[x].getAttribute("val") == srchTerms) //if there is a matching number then...
{
if(!document.getElementById("resultImg")) //check if image exists already and if it doesnt create one, otherwise just swap them
{
var result = document.getElementById("result")
var img = document.createElement("img");
img.src = "donotcall.bmp";
img.id = "resultImg";
result.appendChild(img);
}
else
{
document.getElementById("resultImg").src = "donotcall.bmp";
}
found = 1; //set found to true if the number matches
break; //break out of the loop when done
}
else
{
found = 0; //set found to false if there is not a match and then outside the loop do same image swap as above
}
}
}
}
if(found == 0)
{
if(!document.getElementById("resultImg"))
{
var result = document.getElementById("result")
var img = document.createElement("img");
img.src = "oktocall.bmp";
img.id = "resultImg";
result.appendChild(img);
}
else
{
document.getElementById("resultImg").src = "oktocall.bmp";
}
}
}
This code works great for small XML documents, but the one I just received that I need to search is like 26MB and that would take forever. I was wondering if there is a faster way to do this with either JS or if not then maybe PHP? The only thing I could tyhink of so far is to just separate the large file into multiple smaller files...
Hope someone can help, and thanks!