Listing du fichier litdemoxml.js
00001// (gH) -_- litdemoxml.js ; TimeStamp (unix) : 28 Décembre 2009 vers 20:07
00002
00003 function sho(txt) { document.getElementById("demo").firstChild.data += txt }
00004
00005 // ##############################################################################
00006
00007 function demoxml() {
00008
00009 // ##############################################################################
00010
00011 var xhr;
00012
00013 try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
00014 catch (e) {
00015 try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
00016 catch (e2) {
00017 try { xhr = new XMLHttpRequest(); }
00018 catch (e3) { xhr = false; }
00019 }
00020 } // fin du catch
00021
00022 xhr.onreadystatechange = function() {
00023
00024 if (xhr.readyState == 4) {
00025 if (xhr.status == 200) {
00026
00027 document.getElementById("demo").setAttribute("class","cadre tarose") ;
00028
00029 dct = xhr.responseXML ;
00030 tab = dct.getElementsByTagName("article") ;
00031 nba = tab.length ;
00032
00033 document.getElementById("demo").firstChild.data = ""
00034 sho("\nLe fichier " + url + " contient " + nba + " articles.\n\n") ;
00035 erln1 = new RegExp(" ","g")
00036 erln2 = new RegExp("(\n|\r)","g")
00037
00038 for (ide=0;ide<tab.length;ide++) {
00039
00040 msg = " Element numéro " + (ide+1) + " (indice " + ide +")\n"
00041 sho(msg)
00042 sho(" ---------------------------\n\n")
00043
00044 var article = tab[ide] ; // article courant
00045 var nbattri = article.attributes.length
00046 var nbenfan = article.childNodes.length
00047 sho(" cet élément a " + nbattri + " attributs et " + nbenfan + " enfants.\n\n")
00048
00049 for (ida=0;ida<nbattri;ida++) {
00050 sho(" Attribut indice " + ida + " : ")
00051 sho(" de nom '" + article.attributes[ida].name + "'")
00052 sho(" et de valeur '" + article.attributes[ida].value + "'")
00053 sho("\n")
00054 } ; // fin pour ida
00055
00056 sho("\n")
00057
00058 for (indc=0;indc<nbenfan;indc++) {
00059 currentElementChild=article.childNodes[indc];
00060 sho(" Enfant indice " + indc)
00061 sho(" nodeType est '" + currentElementChild.nodeType + "' ; ")
00062 sho(" nodeName est '" + currentElementChild.nodeName + "' ; ")
00063 if (currentElementChild.nodeValue == null) {
00064 sho(" nodeValue est '" + currentElementChild.nodeValue + "' ; ")
00065 } else { // on essaie de supprimer les \n
00066 valeur = currentElementChild.nodeValue
00067 valeur = valeur.replace(erln1,"")
00068 valeur = valeur.replace(erln2,"\\n")
00069 sho(" nodeValue est '" + valeur + "' ; ")
00070 } ; // fin de si
00071 sho(" text est '" + currentElementChild.text + "' ; ")
00072 if (currentElementChild.childNodes.length>0) {
00073 sho(" childNodes[0].data est '" + currentElementChild.childNodes[0].data + "' ; ")
00074 } ; // fin si
00075 sho("\n")
00076 } ; // fin pour indc
00077
00078 sho("\n")
00079
00080 } ; // fin pour ide
00081
00082 } ; // fin de xhr.status == 200
00083 } ; // fin de xhr.readyState == 4
00084
00085 } ; // fin de fonction xhr.onreadystatechange
00086
00087 var url = "demo.xml" ;
00088 xhr.open("GET", url, true);
00089 xhr.send(null);
00090
00091 } ; // fin de fonction demoxml
00092
00093 // ##############################################################################
00094
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)