If you are free to change the XML format, are you free to change it
completely?

Could you change it to HTML instead, and format the HTML in the same way
that you are doing in JavaScript now? Then you could simply use
$('#content_window_pages').load(...); and it would be very fast.

Or you could use JSON instead of XML and speed it up a lot, but HTML would
be by far the fastest.

Is either of those changes - to HTML or JSON - feasible? XML is the worst
choice for this kind of operation.

-Mike

> From: Martin Tiršel
> 
> Hello,
> 
> I get XML answer from server with ~5k lines and I need to 
> parse this data into the table and display in HTML. I wrote a 
> script to do this job, but it takes too much time to complete 
> (~35 seconds in opera), what is not I want. Is there a way to 
> improve this script? Perhaps there is more effective way to do this.
> 
> XML looks like:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <xmldata>
> <page>
>    <name>ebapylibnfwxorjwoeseksnyqumdmxssaduy</name>
>    <id>5</id>
>    <url>ojosjkfujggkildmlr</url>
>    <author>
>      <id>7</id>
>      <name>b</name>
>    </author>
>    <languages>
>        <lang>sk</lang>
>        <lang>cz</lang>
>    </languages>
> </page>
> ... 500x similar as above
> </xmldata>
> 
> JS:
> 
> ...
>      var table = '<table
> class="pagelist"><thead><tr><th>Name</th><th>Author</th><th>La
> nguages</th><th>Actions</th></tr></thead><tbody>';
> 
>      $(xml).find("page").each(function(i) {
>        var name = $(this).find("name").text();
>        var author = $(this).find("author name").text();
>        var languages = new Array();
>        $(this).find("languages lang").each(function() {
>          languages.push($(this).text());
>        });
>        languages = languages.join(',');
>        table += '<tr><td class="first">' + name + '</td><td 
> class="second">' + author + '</td><td class="third">' + 
> languages + '</td><td class="fourth">&nbsp;</td></tr>';
>      });
> 
>      table += '</tbody></table>';
> 
>      $("#content_window_pages").append(table);
> ...
> 
> XML structure can be changed if it helps to speed up the script.
> 
> Thanks for any suggestions,
> Martin
> 

Reply via email to