1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| //@Doc xml
//@Element type
//@domposition = Position de la table dans le document
function tableau (xmldoc,elxml,idposition)
{
//Quelques nodeList utiles pour la suite
var record = xmlDoc.getElementsByTagName(elxml); //Array des elements type
//Se positionner dans le document
var pos = document.getElementById(idposition);
//Modification de la table
var mytable = document.createElement('table'); //Je crée l'élément
pos.appendChild(mytable); //Je l'insère
var table = pos.lastChild ; //Je crée la variable chemin pour y accéder
//Entete
var mytr = document.createElement('tr');
table.appendChild(mytr);
var tr = table.lastChild ;
for(x = 0 ; x < record[0].childNodes.length ; x++) //On compte le nombre de champ par record
{
//Gestion des <th>
var myth = document.createElement('th');
tr.appendChild(myth);
var th = tr.lastChild ;
//Valeur des <td>
txt = document.createTextNode(record[0].childNodes[x].nodeName);
th.appendChild(txt);
}
//Corps
for(y = 0 ; y < record.length ; y++) //On boucle sur les lignes
{
var mytr = document.createElement('tr');
table.appendChild(mytr);
var tr = table.lastChild ;
for(x = 0 ; x < record[0].childNodes.length ; x++) //On boucle sur les colonnes
{
//Gestion des <td>
mytd = document.createElement('td');
tr.appendChild(mytd);
var td = tr.lastChild ;
//Valeur des <td>
txt = document.createTextNode(record[y].childNodes[x].firstChild.nodeValue);
td.appendChild(txt);
}
}
} |
Partager