IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

[DOM] DOM xml firefox et ie


Sujet :

JavaScript

  1. #1
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut [DOM] DOM xml firefox et ie
    Bonjour,

    je cherche un site ou script afin de faire un code commun (qui marche a la fois avec firefox et ie, opera...) lorsque j'utilise dom xml avec javascript lorsque je veux parser un fichier XML.


    Quelqu'un a t il une idee ?

    merci a vous

  2. #2
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    euh peut tu en dire plus car la c'est un peu flou.

    Tu n'aurais pas un ti bout de code ?

  3. #3
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    j'essaye de trouver des equivalences entre ie et firefox. et ca ne marche pas toujours.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    if (document.implementation && document.implementation.createDocument){
          	strTitre = collectionlivre[i].childNodes[1].firstChild.nodeValue;
          	strISBN = collectionlivre[i].attributes[1].nodeValue;
          	//strEditeur = collectionlivre[i].childNodes[4].firstChild.nodeValue;
          }else if (window.ActiveXObject){
          	strTitre = collectionlivre[i].childNodes[0].firstChild.nodeValue;
          	strISBN = collectionlivre[i].attributes[1].nodeValue;
          	strEditeur = collectionlivre[i].childNodes[2].firstChild.nodeValue;
          }
    [/code]

  4. #4
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    alors un peu de lecture que tu devrais trouver interressante :
    http://javascript.developpez.com/faq...M#DOMIEFirefox

    et des réponses :
    http://www.developpez.net/forums/vie...r=asc&start=11

  5. #5
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    merci, mais comme je veux parcourir un fichier XML externe que dois je mettre a la place de '*' dans document.getElementsByTagName('*') et a quelle endroit ?

  6. #6
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    mon fichier XML ressemble a ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    <librairie>
    	<livre prix="cat2" ISBN="2-212-09051-X" code="DG1-0">
    		<titre stock="non">CSS 2</titre>
    		<auteur>Daniel GLAZMAN</auteur>
    		<editeur>Eyrolles</editeur>
    	</livre>
    	<livre prix="cat1" ISBN="2-84082-533-3" code="MJY1-0">
    		<titre stock="oui">XML</titre>
    		<auteur>Michael J. YOUNG</auteur>
    		<editeur>Microsoft Press</editeur>
    		<collection>Formation à...</collection>
    	</livre>
    	<livre prix="cat1" ISBN="2-84082-865-0" code="RC1-0">
    		<titre stock="non">ASP.Net</titre>
    		<auteur autrespub="RC2-0">Richard CLARK</auteur>
    		<editeur>Microsoft Press</editeur>
    		<collection>Formation à...</collection>
    	</livre>
    </librairie>
    et mon javascript

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Initiation à XML : Liaison de données</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- <script language="JavaScript" type="text/javascript" for="window" event="onload"> -->
    <script language="JavaScript" type="text/javascript">
       i = 0;
       function fDisplayLivre(){
          doc = document.getElementById("dso16").XMLDocument;
          var strAuteur="";
     
          // Récupération de tous les noeuds LIVRE du document
          collectionlivre = doc.documentElement.getElementsByTagName("livre");
          nbrlivre = collectionlivre.length;
     
          i = (i>collectionlivre.length -1) ? collectionlivre.length -1 : i ;
          i = (i<0) ? 0 : i ;
     
          // Récupération du TITRE, de l'ISBN et de l'EDITEUR pour le livre courant
          strTitre = collectionlivre.item(i).childNodes(0).text;
          strISBN = collectionlivre.item(i).childNodes(0).attributes(0).nodeValue;
          strEditeur = collectionlivre.item(i).getElementsByTagName("editeur").item(0).text;
     
          // Récupération de tous les noeuds AUTEUR pour le livre courant
          collectionauteur = collectionlivre.item(i).getElementsByTagName("auteur");
          nbrauteur = collectionauteur.length;
          for(aut=0;aut<nbrauteur;aut++){
             strAuteur = strAuteur + collectionauteur.item(aut).text + "<br />";
          }
     
          // Récupération de la COLLECTION s'il y en a une pour le livre courant
          if(collectionlivre.item(i).getElementsByTagName("collection").length!=0){
             strCollection = collectionlivre.item(i).getElementsByTagName("collection").item(0).text;
          } else {
             strCollection = "";
          }
     
          // Affichage de l'image de couverture s'il y en a une pour le livre courant
          if(collectionlivre.item(i).childNodes(0).attributes(1)!=null){
             couverture.src = collectionlivre.item(i).childNodes(0).attributes(1).nodeValue;
          } else {
             couverture.src = "images/blanc.gif";
          }
     
          // Affichage de l'ensemble des informations du livre courant
          livre.innerHTML = "<span style='font: bold 14px;'>" + strTitre + "</span><br />"
                      + "<span>ISBN : </span><span style='color: #ff6900'>" + strISBN + "</span><br />"
                      + "<span>Auteur(s) : </span><br /><span style='font: bold 10px;'>" 
                      + strAuteur + "</span><br />"
                      + "<span>Edition : </span><span>" + strEditeur + "</span><br />"
                      + "<span>Collection : </span><span>" + strCollection + "</span>"
     
       }
    </script>
    </head>
     
    <body onload="fDisplayLivre();">
       <xml id="dso16" src="librairie.xml" />
       <table border="0" cellspacing="0" cellpadding="5">
          <tr>
             <td width="100" height="100" align="left" valign="middle">
                <img id="couverture" border="0" />
             </td>
             <td align="left" valign="top" style="font: 10px verdana">
                <span id="livre" style="font: 10px verdana;" />
             </td>
          </tr>
          <tr>
             <td style="font: 11px verdana" align="left">
                <a href="#" onclick="fDisplayLivre(i--)"> &lt;&lt; Livre précédent</a>
             </td>
             <td style="font: 11px verdana" align="right">
                <a href="#" onclick="fDisplayLivre(i++)">Livre suivant &gt;&gt;</a>
             </td>
          </tr>
       </table>
    </body>
    </html>
    avec ie c impec.

  7. #7
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    a mon avis c est sur ta variable doc.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    function go(c){
    	if(!c.data.replace(/\s/g,''))
    		c.parentNode.removeChild(c);
    }
     
    function clean(d){
    	var bal=d.getElementsByTagName('*');
     
    	for(i=0;i<bal.length;i++){
    		a=bal[i].previousSibling;
    		if(a && a.nodeType==3)
    			go(a);
    		b=bal[i].nextSibling;
    		if(b && b.nodeType==3)
    			go(b);
    	}
    	return d;
    }
    i = 0;
       function fDisplayLivre(){
          doc = clean(document.getElementById("dso16").XMLDocument);

  8. #8
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    marche toujours pas.

    sous ie il me mets directement sur mon dernier noeud et sous firefox toujours rien !!!!!

  9. #9
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    alors j'ai une bonne nouvelle

    rajoutes juste un encoding="iso-8859-1" dans ton prologue xml, ou enlève les à

  10. #10
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    y avait deja cette balise.

    ca ne fonctionne ni sur ie ni sur firefox, je n'y comprends plus rien !!!!

    Je ne sais plus quoi faire

  11. #11
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    en mettant le encoding dans le fichier xml, ou en enlevant les "à" du même fichier, ton code marche chez moi

  12. #12
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    dans mon xml il y avait deja le tag pour l'encoding.

    Pour ma part a l'ouverture de ma page ca affiche le dernier noeud de mon xml.

    Arrive tu a naviguer ?

  13. #13
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    oui

  14. #14
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    peux tu me mettre ton code a dispo stp ?

    merci a toi

  15. #15
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    c est le tien !!!!
    avec un encoding dans le xml

    enfin je croit que j'ai rien modifié (me souviens plus)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Initiation à XML : Liaison de données</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- <script language="JavaScript" type="text/javascript" for="window" event="onload"> -->
    <script language="JavaScript" type="text/javascript">
       i = 0;
       function fDisplayLivre(){
          doc = document.getElementById("dso16").XMLDocument;
          var strAuteur="";
     
          // Récupération de tous les noeuds LIVRE du document
          collectionlivre = doc.documentElement.getElementsByTagName("livre");
          nbrlivre = collectionlivre.length;
     
          i = (i>collectionlivre.length -1) ? collectionlivre.length -1 : i ;
          i = (i<0) ? 0 : i ;
     
          // Récupération du TITRE, de l'ISBN et de l'EDITEUR pour le livre courant
          strTitre = collectionlivre.item(i).childNodes(0).text;
          strISBN = collectionlivre.item(i).childNodes(0).attributes(0).nodeValue;
          strEditeur = collectionlivre.item(i).getElementsByTagName("editeur").item(0).text;
     
          // Récupération de tous les noeuds AUTEUR pour le livre courant
          collectionauteur = collectionlivre.item(i).getElementsByTagName("auteur");
          nbrauteur = collectionauteur.length;
          for(aut=0;aut<nbrauteur;aut++){
             strAuteur = strAuteur + collectionauteur.item(aut).text + "<br />";
          }
     
          // Récupération de la COLLECTION s'il y en a une pour le livre courant
          if(collectionlivre.item(i).getElementsByTagName("collection").length!=0){
             strCollection = collectionlivre.item(i).getElementsByTagName("collection").item(0).text;
          } else {
             strCollection = "";
          }
     
          // Affichage de l'image de couverture s'il y en a une pour le livre courant
          if(collectionlivre.item(i).childNodes(0).attributes(1)!=null){
             couverture.src = collectionlivre.item(i).childNodes(0).attributes(1).nodeValue;
          } else {
             couverture.src = "images/blanc.gif";
          }
     
          // Affichage de l'ensemble des informations du livre courant
          livre.innerHTML = "<span style='font: bold 14px;'>" + strTitre + "</span><br />"
                      + "<span>ISBN : </span><span style='color: #ff6900'>" + strISBN + "</span><br />"
                      + "<span>Auteur(s) : </span><br /><span style='font: bold 10px;'>"
                      + strAuteur + "</span><br />"
                      + "<span>Edition : </span><span>" + strEditeur + "</span><br />"
                      + "<span>Collection : </span><span>" + strCollection + "</span>"
     
       }
    </script>
    </head>
     
    <body onload="fDisplayLivre();">
       <xml id="dso16" src="librairie.xml" />
       <table border="0" cellspacing="0" cellpadding="5">
          <tr>
             <td width="100" height="100" align="left" valign="middle">
                <img id="couverture" border="0" />
             </td>
             <td align="left" valign="top" style="font: 10px verdana">
                <span id="livre" style="font: 10px verdana;" />
             </td>
          </tr>
          <tr>
             <td style="font: 11px verdana" align="left">
                <a href="#" onclick="fDisplayLivre(i--)"> &lt;&lt; Livre précédent</a>
             </td>
             <td style="font: 11px verdana" align="right">
                <a href="#" onclick="fDisplayLivre(i++)">Livre suivant &gt;&gt;</a>
             </td>
          </tr>
       </table>
    </body>
    </html>
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    <?xml version="1.0" encoding="iso-8859-1"?>
    <librairie>
       <livre prix="cat2" ISBN="2-212-09051-X" code="DG1-0">
          <titre stock="non">CSS 2</titre>
          <auteur>Daniel GLAZMAN</auteur>
          <editeur>Eyrolles</editeur>
       </livre>
       <livre prix="cat1" ISBN="2-84082-533-3" code="MJY1-0">
          <titre stock="oui">XML</titre>
          <auteur>Michael J. YOUNG</auteur>
          <editeur>Microsoft Press</editeur>
          <collection>Formation à...</collection>
       </livre>
       <livre prix="cat1" ISBN="2-84082-865-0" code="RC1-0">
          <titre stock="non">ASP.Net</titre>
          <auteur autrespub="RC2-0">Richard CLARK</auteur>
          <editeur>Microsoft Press</editeur>
          <collection>Formation à...</collection>
       </livre>
    </librairie>

  16. #16
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    Moi ca ne marche toujours pas, j'ai les meme problemes. bizarre que ca puisse marcher chez toi. je comprend encore moins

  17. #17
    Expert confirmé
    Avatar de siddh
    Inscrit en
    Novembre 2005
    Messages
    3 868
    Détails du profil
    Informations personnelles :
    Âge : 48

    Informations forums :
    Inscription : Novembre 2005
    Messages : 3 868
    Points : 5 011
    Points
    5 011
    Par défaut
    alors plusieurs trucs a faire :
    - le faire essayer sur d'autres machines (la mienne xp pro et ie 6 sp2)
    - vider ton cache et réessayer

Discussions similaires

  1. [DOM] DOM XML, ne marche pas sous Firefox
    Par Nass2 dans le forum Général JavaScript
    Réponses: 13
    Dernier message: 21/06/2008, 10h28
  2. [DOM] Validation xml avec PHP
    Par thefaycal dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 26/01/2006, 21h15
  3. [DOM] Parsage XML en PHP 4
    Par Huntress dans le forum Bibliothèques et frameworks
    Réponses: 7
    Dernier message: 07/12/2005, 22h24
  4. [JAXB/DOM] Parser Xml : possible avec path reel et non uri !
    Par Jaxofun dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 01/08/2005, 10h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo