// (gH) -_- litdemoxml.js ; TimeStamp (unix) : 28 Décembre 2009 vers 20:07
function sho(txt) { document.getElementById("demo").firstChild.data += txt }
// ##############################################################################
function demoxml() {
// ##############################################################################
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e) {
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2) {
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
} // fin du catch
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
document.getElementById("demo").setAttribute("class","cadre tarose") ;
dct = xhr.responseXML ;
tab = dct.getElementsByTagName("article") ;
nba = tab.length ;
document.getElementById("demo").firstChild.data = ""
sho("\nLe fichier " + url + " contient " + nba + " articles.\n\n") ;
erln1 = new RegExp(" ","g")
erln2 = new RegExp("(\n|\r)","g")
for (ide=0;ide<tab.length;ide++) {
msg = " Element numéro " + (ide+1) + " (indice " + ide +")\n"
sho(msg)
sho(" ---------------------------\n\n")
var article = tab[ide] ; // article courant
var nbattri = article.attributes.length
var nbenfan = article.childNodes.length
sho(" cet élément a " + nbattri + " attributs et " + nbenfan + " enfants.\n\n")
for (ida=0;ida<nbattri;ida++) {
sho(" Attribut indice " + ida + " : ")
sho(" de nom '" + article.attributes[ida].name + "'")
sho(" et de valeur '" + article.attributes[ida].value + "'")
sho("\n")
} ; // fin pour ida
sho("\n")
for (indc=0;indc<nbenfan;indc++) {
currentElementChild=article.childNodes[indc];
sho(" Enfant indice " + indc)
sho(" nodeType est '" + currentElementChild.nodeType + "' ; ")
sho(" nodeName est '" + currentElementChild.nodeName + "' ; ")
if (currentElementChild.nodeValue == null) {
sho(" nodeValue est '" + currentElementChild.nodeValue + "' ; ")
} else { // on essaie de supprimer les \n
valeur = currentElementChild.nodeValue
valeur = valeur.replace(erln1,"")
valeur = valeur.replace(erln2,"\\n")
sho(" nodeValue est '" + valeur + "' ; ")
} ; // fin de si
sho(" text est '" + currentElementChild.text + "' ; ")
if (currentElementChild.childNodes.length>0) {
sho(" childNodes[0].data est '" + currentElementChild.childNodes[0].data + "' ; ")
} ; // fin si
sho("\n")
} ; // fin pour indc
sho("\n")
} ; // fin pour ide
} ; // fin de xhr.status == 200
} ; // fin de xhr.readyState == 4
} ; // fin de fonction xhr.onreadystatechange
var url = "demo.xml" ;
xhr.open("GET", url, true);
xhr.send(null);
} ; // fin de fonction demoxml
// ##############################################################################
|