fastest way to load and process 100 rows variable

T

TKapler

I got a javasscript based aplication, which is working with data from
server (php&sql, changed once per week or so). Actualy I use a xml as a
data format with structure e.g.
[item var1="smthng" var2="123" var3="456" var4="ABC" /]
I open read the file through XMLHttpRequest and then i do smtg like

items = documentElement.getElementsByTagName("item");
for i=0 to items.lenght {
var1=item.getAttribute("var1")
....
function(var1, var2, var3, var4)
}

The problem is, that it is quite slow with 100 items i'am sometimes
over 5 secs total execution time on firefox and it than write an error
message. The others browsers do not write this message, but they are
even slower, up to 20 secs for IE
The slow thing is that file access and making a variable from it.

If wonder that there may be some much faster way, as i do not need the
data to be in xml, i can make any data format, i can even make
something like var dump. But i do not know how to parse this dump to
variable, and i do not know if it will be faster

Or are there some other fast ways how to quicker load the data?
 
R

RobG

TKapler said:
I got a javasscript based aplication, which is working with data from
server (php&sql, changed once per week or so). Actualy I use a xml as a
data format with structure e.g.
[item var1="smthng" var2="123" var3="456" var4="ABC" /]
I open read the file through XMLHttpRequest and then i do smtg like

items = documentElement.getElementsByTagName("item");
for i=0 to items.lenght {
var1=item.getAttribute("var1")
...
function(var1, var2, var3, var4)
}

The problem is, that it is quite slow with 100 items i'am sometimes
over 5 secs total execution time on firefox and it than write an error
message. The others browsers do not write this message, but they are
even slower, up to 20 secs for IE
The slow thing is that file access and making a variable from it.

If wonder that there may be some much faster way, as i do not need the
data to be in xml, i can make any data format, i can even make
something like var dump. But i do not know how to parse this dump to
variable, and i do not know if it will be faster

Or are there some other fast ways how to quicker load the data?


Try JSON:

<URL: http://www.json.org/ >

e.g.

// jsonTxt is returned by the XMLHttpRequest
// Preferrably machine generated, getting the syntax right
// can be tricky if done manually
var jsonTxt =
'{'
+ 'item0 : ["smthng", "123", "456", "ABC"],'
+ 'item1 : ["nudder", "asd", "dfgh", "D"],'
+ 'item2 : ["anudder", "lkj", "oiu", "E"]'
+ '}';

var items = eval( '(' + jsonTxt + ')' );

function showArgs(){
var args = [];
for (var i=0; i<arguments.length; i++){
args.push(arguments);
}
alert(args.join('\n'));
}

showArgs(items.item1[0], items.item1[1], items.item1[2]);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top