Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ajax][xml][prototype] Parsowanie xmla i podwojony krok pętli
yaro
post
Post #1





Grupa: Zarejestrowani
Postów: 160
Pomógł: 4
Dołączył: 22.04.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Mam mały problem z parsowaniem xml-a.
Mam pięć elementów w xml-u a musze podać że mam 10 i krok pętli zwiększyć do 2, żeby 'skakała' co 2.
Nie rozumiem dlaczego sie tak dzieje (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Poniżej daje kod.

  1. <TR>
  2. <TD>N.</TD>
  3. <TD>Data:</TD>
  4. <TD>Rozmiar:</TD>
  5. <TD>Od:</TD>
  6. <TD>Temat:</TD>
  7. </TR>
  8. </thead>
  9. <tbody id="mails">
  10. </tbody>
  11. </TABLE>


Kod
function getHTML()
{
    var url = 'test.xml';
    var myAjax = new Ajax.Request( url, { onComplete: showResponse });
}

function showResponse(originalRequest)
{
    //$('mails').innerHTML = originalRequest.responseText;
    d = $("mails");
    record = originalRequest.responseXML.getElementsByTagName("record");
    for (i = 0; i < record.length; i++) {
        tr = document.createElement("tr");
        td = document.createElement("td");
        for (j = 1; j < 10; j+=2) {  // w tej linii musiałem podwoić krok pętli
            td = document.createElement("td");
            td.innerHTML = record[i].childNodes[j].childNodes[0].nodeValue;
            tr.appendChild(td);
        }
        d.appendChild(tr);
    }
}


test.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <records>
  3. <record>
  4. <imie>1</imie>
  5. <nazwisko>2</nazwisko>
  6. <cos>3</cos>
  7. <cos2>4</cos2>
  8. <cos3>5</cos3>
  9. </record>
  10. </records>


Dodam że problem jest chyba w przeglądarkach innych niż ie

Ten post edytował yaro 30.07.2006, 17:57:25
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 04:36