- Kod: Zaznacz cały
var xmlDocument = httpRequest.responseXML.documentElement;
var from = xmlDocument.getElementsByTagName ("from")[0].firstChild.data;
var to = xmlDocument.getElementsByTagName ("to")[0].firstChild.data;
var info = xmlDocument.getElementsByTagName ("info")[0].firstChild.data;
var source = xmlDocument.getElementsByTagName ("source")[0].firstChild.data;
var url = xmlDocument.getElementsByTagName ("url")[0].firstChild.data;
var pronunciation = xmlDocument.getElementsByTagName ("pronunciation")[0].firstChild.data;
var text = "<p>INFO: " + info + "</p>Źródło: " + source + "<br />";
text = text + "<a href=" + url + " target=_blank>" + url + "</a><br />";
text = text + "<table><tr><td>l.p.</td><td>" + from + "</td><td>" + to + "</td>";
if (pronunciation == "yes")
text = text + "<td>Wymowa</td>";
text = text + "</tr>"
words = xmlDocument.getElementsByTagName ("word");
for (i = start; i < start + 100; i++) {
if (!words[i]) break;
from = words[i].getElementsByTagName ("from")[0].firstChild.data;
to = words[i].getElementsByTagName ("to")[0].firstChild.data;
text = text + "<tr><td>" + eval (i + 1) + "</td><td>" + from + "</td><td>" + to + "</td>";
if (pronunciation == "yes") {
pro = words[i].getElementsByTagName ("pronunciation")[0].firstChild.data;
text = text + "<td>" + pro + "</td>";
}
text = text + "</tr>";
}
text = text + "</table>";
writeText (text, "list");
Kawałek pliku XML:
- Kod: Zaznacz cały
<?xml version='1.0' encoding='utf-8' ?>
<list>
<from>ang</from>
<to>pl</to>
<info>Informacje</info>
<source>Źródło</source>
<url>link</url>
<pronunciation>yes</pronunciation>
<word>
<from>I</from>
<to>ja</to>
<pronunciation>aj</pronunciation>
</word>
<word>
<from>You</from>
<to>ty, wy</to>
<pronunciation>ju</pronunciation>
</word>
</list>
I tak, gdy plik jest taki jak w podanym przeze mnie przykładzie, wszystko idzie ok. Jednak gdy się trochę rozrośnie, do 1000 elementów WORD, to się wykrzacza. Konsola błędów wywala już błąd:
Błąd: xmlDocument.getElementsByTagName("info")[0] has no properties
Plik źródłowy: http://localhost/1000slow/js.js
Wiersz: 25
Czyli w miejscu, które jest identyczne, co w krótkiej wersji pliku. Nie rozumiem co jest nie tak. Może ktoś pomóc? Może plik jest za długi bądź ja czegoś nie umiem?
pozdrawiam,
Piotr Misiurek
[wycinam spam /moderator]