[DOM] noeud vide sous firefox
Salut a tous , j'essaye de récupèrer l'arborescence d'un noeud xml via le dom, mais je me confronte a un problème , firefox plante sur un :
x.nextSibling , si x = un noeud = a '\n '
le code js :
Code:
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 54 55 56 57 58 59
|
var xmlDoc = "";
function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async=false;
xmlDoc.load("gabarit.xml");
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async=false;
xmlDoc.load("gabarit.xml");
if (xmlDoc.parseError.errorCode != 0)
alert("Error loading XML file : " + xmlDoc.parseError.reason);
else{}
//alert (xmlDoc.xml);
}
else
{
alert('Your browser can\'t handle this script');
return;
}
getVersion();
}
function getVersion(){
arborescence(xmlDoc.getElementsByTagName('galeries')[0]);
}
function arborescence(noeudCourant){
x = noeudCourant ;
var temp ="";
while(x){
if(x.nodeType == 1){
temp += "Nom : " + x.nodeName+"<br />";
}
try{
if(x.firstChild.nodeType == 1){
x = x.firstChild;
}
else if(x.firstChild.nextSibling != null){
x = x.firstChild.nextSibling;
}
else
{
x = x.nextSibling;
}
}
catch(e){
alert("error");
}
}
document.getElementById('final').innerHTML = temp;
} |
le fichier xml :
Code:
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
|
<?xml version="1.0" encoding="UTF-8"?>
<galeries>
<galerie>
<id>1</id>
<description>
<titre>première galerie</titre>
<auteur>moi</auteur>
<dateCreation>26/10/2007</dateCreation>
<theme>animaux</theme>
</description>
<images>
<image>
<id>1</id>
<link>blabla</link>
<description>de l'image</description>
<taille h="120" w="150" />
<poid>200ko</poid>
</image>
<image>
<id>2</id>
<link>blabla</link>
<description>de l'image</description>
<taille h="120" w="150" />
<poid>200ko</poid>
</image>
</images>
</galerie>
</galeries> |
Code html :
Code:
1 2 3 4 5
|
<form>
<input type="button" name="test" value="click" onclick="importXML()" />
</form>
<div id="final"></div> |
sous ie aucun souçis ....
je débug depuis une heure sous firebug et je ne trouve pas de solution ...