Listing du fichier exemple3.js
00001// (gH) -_- exemple3.js ; TimeStamp (unix) : 16 Octobre 2009 vers 15:13
00002
00003 // ###############################################################
00004
00005 function sousArbreDom(currentElement, depth,attr) {
00006
00007 // ###############################################################
00008
00009 tdd = typeof(depth) ; if (tdd=="undefined") { depth = 1 }
00010 if (typeof(attr)=="undefined") { attr = 1 }
00011
00012 rt = "" // initialisation de la chaine à renvoyer
00013
00014 // ceci constitue le critère d'arret
00015
00016 if (currentElement) {
00017
00018 var tagName=currentElement.tagName;
00019
00020 // on écrit la balise comme <a>, <img>, etc
00021 if (tagName) {
00022 if (depth>=1) {
00023 rt += "<"+currentElement.tagName.toLowerCase()
00024 // il faut maintenant récupérer les attributs non nuls de la balise
00025 if (attr==1) {
00026 attrs = ""
00027 nbac = currentElement.attributes.length
00028 if (nbac>0) {
00029 for (ida=0; ida<currentElement.attributes.length;ida++ ) {
00030 curn = currentElement.attributes[ida].name
00031 curv = currentElement.attributes[ida].value
00032 ok = 1
00033 if (typeof(curv)=='undefined') { ok = 0 }
00034 if (curv=='null') { ok = 0 }
00035 if (!curv) { ok = 0 }
00036 if (curv==null) { ok = 0 }
00037 if (curv==0) { ok = 0 }
00038 if (curv=='') { ok = 0 }
00039 if (ok==1) {
00040 attrs += " " + curn + "='" + curv + "'";
00041 } // fin si
00042 } // fin pour
00043 } // fin si
00044 rt += attrs
00045 } // fin si
00046 } // fin si
00047 } else {
00048 cv = currentElement.nodeValue
00049 rt += cv
00050 } // fin de si
00051
00052 if (tagName) {
00053 if (depth>=1) {
00054 rt += ">"
00055 } // fin si
00056
00057 // traversée récursive de l'arbre
00058
00059 var indc=0;
00060 var enfant=0;
00061 var currentElementChild=currentElement.childNodes[indc];
00062 while (currentElementChild) {
00063 // traversée récursive du sous-arbre du noeud enfant
00064 rt += sousArbreDom(currentElementChild, depth+1,attr);
00065 indc++;
00066 currentElementChild=currentElement.childNodes[indc];
00067 } // fin de tant que
00068
00069 // fermeture éventuelle de la balise
00070
00071 if (tagName) {
00072 if (depth>=1) {
00073 rt += "</"+tagName.toLowerCase()+">";
00074 } // fin si
00075 } // fin si
00076 } // fin si
00077
00078 } // fin de si currentElement
00079
00080 return( rt )
00081
00082 } // fin de fonction sousArbreDom
00083
00084 // ###############################################################
00085
00086 function sousArbreDomGraphique(currentElement, depth,attr) {
00087
00088 // ###############################################################
00089
00090 tdd = typeof(depth)
00091 if (tdd=="undefined") { depth = 1 }
00092
00093 tda = typeof(attr)
00094 if (tda=="undefined") { attr = 1 }
00095
00096 if (currentElement) {
00097
00098 // -------------------------------------------------------------
00099
00100 var j;
00101 var tagName=currentElement.tagName;
00102
00103 if (tagName) {
00104
00105 ecrit_infos_sansrc("<"+currentElement.tagName.toLowerCase());
00106 if (attr==1) {
00107 // il faut maintenant récupérer les attributs non nuls de la balise
00108 attrs = ""
00109 nbac = currentElement.attributes.length
00110 if (nbac>0) {
00111 for (ida=0; ida<currentElement.attributes.length;ida++ ) {
00112 curn = currentElement.attributes[ida].name
00113 curv = currentElement.attributes[ida].value
00114 ok = 1
00115 if (typeof(curv)=='undefined') { ok = 0 }
00116 if (curv=='null') { ok = 0 }
00117 if (!curv) { ok = 0 }
00118 if (curv==null) { ok = 0 }
00119 if (curv==0) { ok = 0 }
00120 if (curv=='') { ok = 0 }
00121 if (ok==1) {
00122 attrs += " " + curn + "='" + curv + "'";
00123 } // fin si
00124 } // fin pour
00125 ecrit_infos_sansrc(attrs);
00126 } // fin si
00127 } // fin si
00128 ecrit_infos_sansrc(">");
00129
00130 } else {
00131 // ==> ecrit_infos_sansrc("[unknown tag]")
00132 nv = currentElement.nodeValue;
00133 // ne pas afficher retour-charriot (code 10 mais [rc])
00134 if (nv.charCodeAt(0)==10) {
00135 ecrit_infos_sansrc("[rc]")
00136 } else {
00137 ecrit_infos_sansrc(nv)
00138 } // fin si
00139 } ; // fin si
00140
00141 // ---------------- partie récursive -----------------------
00142
00143 var i=0;
00144 var currentElementChild=currentElement.childNodes[i];
00145 while (currentElementChild) {
00146 ecrit_infos_sansrc("\n");
00147 for (j=0; j<depth; j++) {
00148 ecrit_infos_sansrc(" |");
00149 } // fin pour
00150 if (tagName) {
00151 ecrit_infos_sansrc("--");
00152 } // fin si
00153 sousArbreDomGraphique(currentElementChild, depth+1,attr);
00154 i++;
00155 currentElementChild=currentElement.childNodes[i];
00156 } // fintant que
00157
00158 // -------------------------------------------------------------
00159
00160 if (tagName) {
00161 if (depth>=1) {
00162 ecrit_infos_sansrc("\n");
00163
00164 for (j=0; j<depth-1; j++) {
00165 ecrit_infos_sansrc(" |");
00166 } // fin pour
00167 if (depth>1) { ecrit_infos_sansrc(" "); }
00168 } // fin si
00169 ecrit_infos_sansrc("</"+tagName.toLowerCase()+">");
00170 } // fin si
00171
00172 currentElement=0;
00173
00174 } // fin si
00175
00176 } // fin de fonction sousArbreDomGraphique
00177
00178 // ###############################################################
00179
00180
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)