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

XML/XSL et SOAP Discussion :

[XML + javascript]


Sujet :

XML/XSL et SOAP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Par défaut [XML + javascript]
    bonjour,

    j'ai creer un fichier html qui se remplit avec les données d'un xml.

    mais les couleurs sont quand à elles renseignées à l'aide d'une fonction javascript que j'ai nommée couleur().

    voici ce que j'ai fait

    -----------------------------------------------------------------

    [code]
    <html>
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="historique.css" type="text/css">
    <xml id="dsoversion" src="data.xml"></xml>
    <Script language=javascript>
    function couleur (coul, nomDuChamp)
    {
    document.form.val.style.backgroundColor = coul;
    document.form.getElementById(val).value = nomDuChamp;
    }
    </script>

    </head>
    <body>
    <FORM NAME="form">
    <table align=center border=1 class="table-ligne1" width=100% cellpadding=0 datasrc="#dsoversion" datafld="Entete">
    <tr class="table-ligne1" width=100% cellpadding=0>
    <td width=50%>Historique de la machine :</td>
    <td width=50%><span datafld="Champ4"></span>
    </td>
    </tr>
    <tr><td colspan=9>
    <table align=center border=0 class="table-ligne2" width=100% cellpadding=0 datasrc="#dsoversion" datafld="Entete">
    <tr>
    <td width=10%><span datafld="Champ1"></span>
    <td width=10%><span datafld="champ2"></span>
    <td width=10%><span datafld="Champ3"></span>
    <td width=17%><span datafld="champ5"></span>
    <td width=17%><span datafld="champ6"></span>
    <td width=17%><span datafld="champ7"></span>
    <td width=17%><span datafld="champ8"></span>
    <td><span datafld="champ9"></span>
    </td>
    </tr>
    </table>
    </td></tr>
    <tr><td colspan=9>
    <table align=center border=0 class="table-ligne2" width=100% cellpadding=0 datasrc="#dsoversion" datafld="Data">
    <tr>

    <td width=10%><span datafld="Champ1"></span>
    <td width=10%><span datafld="champ2"></span>
    <td width=10%><span datafld="Champ3"></span>
    <td width=17%><span datafld="champ5"></span>
    <td width=17%><span datafld="champ6"></span>
    <td width=17%><input type="text" id="val" name="val" border="0" value="" onChange="couleur(<span datafld='champ4'></span>,<span datafld='champ9'></span>)"><span datafld ='champ7'></span><!-- <span datafld='champ4'></span>,<span datafld='champ9'></span> -->
    <td width=17%><span datafld="champ8"></span>
    <td><span datafld="champ9"></span>
    </td>
    </tr>
    </table>
    </td></tr>
    </table>
    </form>
    </body>
    </html>


    [\code]
    -----------------------------------------------------------------

    je ne comprends pas pourquoi ma fonction couleur ne marche pas????

  2. #2
    Expert confirmé
    Avatar de Swoög
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    6 045
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 6 045
    Par défaut
    Salut !

    alors tout d'abord, pour fermer les bbcode (le [code] notamment), c'est pas un \ mais un / qu'il faut

    ensuite, pour ton code, je ne suis pas sûr que la balise xml soit valide

    je pense qu'une balise
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <script type="application/xml">
    serait mieux adaptée mais bon, c'est juste une idée...

    pour ta fonction javascript, par contre, il faudrait faire untruc comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    document.getElementById("val").style.backgroundColor = coul;
    document.getElementById("val").value = nomDuChamp;
    ensuite, le problème vient également du fait que tu utilises des trucs très bizarres, normalement, il vaut mieux éviter les < et > dans les attributs... (je suis sûr que c'est interdit en XHTML, mais je ne sais plus pour HTML) sans parler des " et ' qui ont l'air utilisés (ou pas) à tort et à travers

    enfin, commence déjà par éditer ton post pour pouvoir mettre des balises code correctes, et puis par modifier ton code javascript, il y aura peut-être moyen de modifier autrement tes balises...
    Rédacteur "éclectique" (XML, Cours PHP, Cours JavaScript, IRC, Web...)
    Les Règles du Forum - Mon Site Web sur DVP.com (Développement Web, PHP, (X)HTML/CSS, SQL, XML, IRC)
    je ne répondrai à aucune question technique via MP, MSN ou Skype : les Forums sont là pour ça !!! Merci de me demander avant de m'ajouter à vos contacts sinon je bloque !
    pensez à la balise [ code ] (bouton #) et au tag :resolu: (en bas)

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Par défaut
    bon alors j'avais bien pensé à écrire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document.getElementById("val").style.backgroundColor
    mais ça ne change pas grand chose..............

    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
     
    <html>
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="historique.css" type="text/css">
    <xml id="dsoversion" src="data.xml"></xml>
    <Script language=javascript>
    function couleur (coul, nomDuChamp)
    {
    document.getElementById("val").style.backgroundColor = coul;
    document.getElementById("val").value = nomDuChamp;
    }
    </script>
     
    </head>
    <body> 
    <FORM NAME="form">
    <table align=center border=1 class="table-ligne1" width=100% cellpadding=0 datasrc="#dsoversion" datafld="Entete">
    <tr class="table-ligne1" width=100% cellpadding=0>
    <td width=50%>Historique de la machine :</td>
    <td width=50%><span datafld="Champ4"></span>
    </td>
    </tr>
    <tr><td colspan=9>
    <table align=center border=0 class="table-ligne2" width=100% cellpadding=0 datasrc="#dsoversion" datafld="Entete">
    <tr>
    <td width=10%><span datafld="Champ1"></span>
    <td width=10%><span datafld="champ2"></span>
    <td width=10%><span datafld="Champ3"></span>
    <td width=17%><span datafld="champ5"></span>
    <td width=17%><span datafld="champ6"></span>
    <td width=17%><span datafld="champ7"></span>
    <td width=17%><span datafld="champ8"></span>
    <td><span datafld="champ9"></span>
    </td>
    </tr>
    </table>
    </td></tr>
    <tr><td colspan=9>
    <table align=center border=0 class="table-ligne2" width=100% cellpadding=0 datasrc="#dsoversion" datafld="Data">
    <tr>
     
    <td width=10%><span datafld="Champ1"></span>
    <td width=10%><span datafld="champ2"></span>
    <td width=10%><span datafld="Champ3"></span>
    <td width=17%><span datafld="champ5"></span>
    <td width=17%><span datafld="champ6"></span>
    <td width=17%><input type="text" id="val" name="val" border="0" value="" onChange="couleur(<span datafld='champ4'></span>,<span datafld='champ9'></span>)"><span datafld ='champ7'></span><!-- <span datafld='champ4'></span>,<span datafld='champ9'></span> -->
    <td width=17%><span datafld="champ8"></span>
    <td><span datafld="champ9"></span>
    </td>
    </tr>
    </table>
    </td></tr>
    </table>
    </form>
    </body>
    </html>
    je n'ai pas la moindre idée de la façon de récupérer la valeur de ma donnée contenue dans mon fichier xml autrement que:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <span datafld='champ4'></span>
    de plus je sais que lors de l'appel de ma fonction couleur(), celle-ci doit avoir des guillemets pour l'attribut coul

    de la façon suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    onChange="couleur( " <span datafld='champ4'></span> " ,<span datafld='champ9'></span>)"
    seulement je m'y perds entre les guillemets simples et doubles

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Par défaut
    j'ai modifié la façon de generer mon fichier html
    j'écris
    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
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
    <html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
    <head>
    <title>Historique</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script language="JavaScript">
    AfficheDocXML();
    function AfficheDocXML()
    {
    var Document;
    Document = new ActiveXObject("Microsoft.XMLDOM");
    Document.async = "false";
    var couleur;
    if(Document.load("data.xml"))
    {
     document.write("<TABLE BORDER=1 CELLPADDING=0>");
     
     for(i=1;i<Document.documentElement.childNodes.length;i++)
     {
             document.write ("<TR ALIGN=center>");
                    for(j=0;j<= 7;j++)
      {
                     document.write ("<TD>");
       if (j != 6)
                     document.write (Document.documentElement.childNodes(i).childNodes(j).text);
     
       if (j == 6)
       {
       couleur = Document.documentElement.childNodes(i).childNodes(6).text;
       //alert(Document.documentElement.childNodes(i).childNodes(6).text);
       document.write (Document.documentElement.childNodes(i).childNodes(7).style.color = couleur);
       }
                             document.write ("</TD>");
                    }
                    document.write ("</TR>");
             }
    document.write ("</TABLE>"); 
    }
    else
    {alert("fichier pas trouvé !");}
    }        
    </script>
    </head>
    <body>
    </body>
    </html>
    j'obtiens l'erreur javascript:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    documentElement.childNodes(...).childNodes(...).style a la valeur null ou n'est pas un objet
    une petite aide serait la bienvenue

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    142
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 142
    Par défaut
    SVP je suis vraiment bloquée

  6. #6
    Expert confirmé
    Avatar de Swoög
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    6 045
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 6 045
    Par défaut
    YO !

    au pire, essaie de faire de alert pour vérifier les valeurs des différents éléments, n'oublie pas que IE considère les noeuds textes blancs (exemple : saut de ligne entre deux balises) comme des noeuds, donc il y a peut-être un problème avec ça
    Rédacteur "éclectique" (XML, Cours PHP, Cours JavaScript, IRC, Web...)
    Les Règles du Forum - Mon Site Web sur DVP.com (Développement Web, PHP, (X)HTML/CSS, SQL, XML, IRC)
    je ne répondrai à aucune question technique via MP, MSN ou Skype : les Forums sont là pour ça !!! Merci de me demander avant de m'ajouter à vos contacts sinon je bloque !
    pensez à la balise [ code ] (bouton #) et au tag :resolu: (en bas)

Discussions similaires

  1. Réponses: 2
    Dernier message: 11/01/2008, 11h05
  2. Sauvegarde web sur Gmail en XML/Javascript
    Par Kamouzo dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 18/10/2007, 13h11
  3. xml & javascript
    Par mounalisa3d dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 27/04/2007, 11h36
  4. [XPATH] [XML] [JAVASCRIPT] Pb de recherche avec apostrophe
    Par lenoil dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 21/02/2006, 14h28
  5. XML, Javascript et balises HTML
    Par Spack dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 16/01/2006, 19h12

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