Salve

Vorrei capire perché dopo aver effettuato il parsing di un file XML (.. XMLHttpRequest ..), il seguente codice funziona correttamente

codice:
for (i=0; i<records; i++)
{
    xmltxt += xmlData.getElementsByTagName("child")[i].children[0].firstChild.nodeValue + " | ";
    xmltxt += xmlData.getElementsByTagName("child")[i].children[1].firstChild.nodeValue + " | ";
    xmltxt += xmlData.getElementsByTagName("child")[i].children[2].firstChild.nodeValue + " | ";
    xmltxt += xmlData.getElementsByTagName("child")[i].children[3].firstChild.nodeValue + " | ";
    xmltxt += xmlData.getElementsByTagName("child")[i].children[4].firstChild.nodeValue + " | <br><hr>";  
}


mentre il seguente no.
TypeError: xmlData.getElementsByTagName(...)[k].children[j] is undefined
codice:
for (k=0; k<records; k++)
{
for(j=0; j<campi; j++) {
Print += xmlData.getElementsByTagName("child")[k].children[j].firstChild.nodeValue + " | ";
}
Print += " | <br><hr>";
}
l'esigenza nasce dal fatto di no saper a priori il numero di campi.

Grazie