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

XSL/XSLT/XPATH XML Discussion :

[XPath]:detecter l'absence d'un attribut


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut [XPath]:detecter l'absence d'un attribut
    Bonjour,
    en utilisant une expression XPath je veux selectionné le premier noeud "display-name" qui a un parent "channel" sans un attribut "id"
    j'ai fait : /tv/channel[count(@id)=0]/display-name[1]
    mais ça marché pas (pb : causé par [count(@id)=0] )

    voici la DTD du fichier xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <!ELEMENT tv (channel*, programme*)>
    <!ELEMENT channel (display-name+, icon*, url*) >
     
    <!ATTLIST channel id CDATA  >
    y a t-il des idées?
    Cdlt.

  2. #2
    Membre émérite
    Avatar de polymorphisme
    Homme Profil pro
    Publishing
    Inscrit en
    Octobre 2009
    Messages
    1 460
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Publishing
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 1 460
    Points : 2 371
    Points
    2 371
    Par défaut
    Bonjour,

    a priori, il n'y a pas de raison que cela ne fonctionne pas !
    Article : Installation de Cocoon
    Je ne réponds pas aux MP à caractère technique.

  3. #3
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut
    lorsque j'enleve la condition [count(@id)=0] tout va bien,
    en mettant cette condition le programme se termine

  4. #4
    Membre émérite
    Avatar de polymorphisme
    Homme Profil pro
    Publishing
    Inscrit en
    Octobre 2009
    Messages
    1 460
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Publishing
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 1 460
    Points : 2 371
    Points
    2 371
    Par défaut
    En fait, pourrait tu nous faire passer tes fichiers tout simplement ...
    Article : Installation de Cocoon
    Je ne réponds pas aux MP à caractère technique.

  5. #5
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut
    voila la methode
    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
     
    void DocRequeteGetConChannel(xmlDocPtr doc,struct _condition *ch){
    //	struct _condition *ch;
    	//ch=(struct _condition*)malloc(sizeof(struct _condition));
    	ch->TabCon=(char**)malloc(20*sizeof(char*)); 
    	ch->nbrCon=0;
    	ch->lenCons=0;
     
    	int lenConCH;
     
    	xmlXPathInit();
    	 xmlXPathContextPtr ctxt = xmlXPathNewContext(doc);
        if (ctxt == NULL) {
            fprintf(stderr, "Erreur lors de la création du contexte XPath\n");
            exit(-1);
        }
    	 // Evaluation de l'expression XPath
     
        //***************************************************************************
        xmlXPathObjectPtr xpathRes = xmlXPathEvalExpression("/requete/channel[@id][count(display-name)=0]", ctxt);
        if (xpathRes == NULL) {
            fprintf(stderr, "Erreur sur l'expression XPath\n");
            exit(-1);
        }
     
        if (xpathRes->type == XPATH_NODESET) {
            int i;
            for (i = 0; i < xpathRes->nodesetval->nodeNr; i++) {
                xmlNodePtr n = xpathRes->nodesetval->nodeTab[i];
                lenConCH=4+strlen((char*)n->properties->children->content);
                ch->lenCons=ch->lenCons+lenConCH;
                ch->TabCon[ch->nbrCon]=(char*)malloc(sizeof(char) *lenConCH);
                strcpy(ch->TabCon[ch->nbrCon],"id=");
                strcat((char*)ch->TabCon[ch->nbrCon],(char*)n->properties->children->content);
                ch->nbrCon=ch->nbrCon+1;
            }
        }
        //printf("/tv/channel[@id][count(display-name)=0]\n");
        //***************************************************************************
          xpathRes = xmlXPathEvalExpression((xmlChar*)"/requete/channel[count(@id)=0]/display-name[1]", ctxt);
        //printf("2\n");
            if (xpathRes == NULL) {
                fprintf(stderr, "Erreur sur l'expression XPath\n");
                exit(-1);
            }
            if (xpathRes->type == XPATH_NODESET) {
                int i;
     
                for (i = 0; i < xpathRes->nodesetval->nodeNr; i++) {
                    xmlNodePtr n = xpathRes->nodesetval->nodeTab[i];
                    lenConCH=14+strlen((char*)n->children->content);
                    ch->lenCons=ch->lenCons+lenConCH;
                    //printf("malloc%d\n",i);
                    ch->TabCon[ch->nbrCon]=(char*)malloc(sizeof(char) *lenConCH);
                    strcpy((char*)ch->TabCon[ch->nbrCon],(const char*)"display-name=");
                    strcat((char*)ch->TabCon[ch->nbrCon],(char*)n->children->content);
                    ch->nbrCon=ch->nbrCon+1;
                }
            }
            //printf("/tv/channel[count(@id)!=1]/display-name[1]\n");
        //***************************************************************************
            xpathRes = xmlXPathEvalExpression("/requete/channel[@id]/display-name[1]", ctxt);
            if (xpathRes == NULL) {
                fprintf(stderr, "Erreur sur l'expression XPath\n");
                exit(-1);
            }
            if (xpathRes->type == XPATH_NODESET) {
                int i;
                for (i = 0; i < xpathRes->nodesetval->nodeNr; i++) {
                    xmlNodePtr n = xpathRes->nodesetval->nodeTab[i];
                    lenConCH=24+strlen((char*)n->children->content)+strlen((char*)n->parent->properties->children->content);
                    ch->lenCons=ch->lenCons+lenConCH;
                    //printf("malloc%d\n",i);
                    ch->TabCon[ch->nbrCon]=(char*)malloc(sizeof(char) *lenConCH);
     
                    strcpy(ch->TabCon[ch->nbrCon],"(display-name=");
                    strcat((char*)ch->TabCon[ch->nbrCon],(char*)n->children->content);
                    strcat(ch->TabCon[ch->nbrCon]," and id=");
                    strcat((char*)ch->TabCon[ch->nbrCon],(char*)n->parent->properties->children->content);
                    strcat(ch->TabCon[ch->nbrCon],")");
                    ch->nbrCon=ch->nbrCon+1;
                }
            }
            //printf("/tv/channel[count(@id)]/display-name[1]\n");
     
     
        // Libération de la mémoire
        xmlXPathFreeObject(xpathRes);
        xmlXPathFreeContext(ctxt);
     
     
    }

  6. #6
    Membre émérite
    Avatar de polymorphisme
    Homme Profil pro
    Publishing
    Inscrit en
    Octobre 2009
    Messages
    1 460
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Publishing
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 1 460
    Points : 2 371
    Points
    2 371
    Par défaut
    ok ok, bon, du côté XPath, il n'y a pas de soucis ca fonctionne.

    Après, je n'ai pas trop le temps de mon plonger dans les lignes de code !

    Bon courage.
    Article : Installation de Cocoon
    Je ne réponds pas aux MP à caractère technique.

  7. #7
    Rédacteur

    Avatar de Erwy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2003
    Messages
    4 967
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 967
    Points : 10 927
    Points
    10 927
    Par défaut
    ca peut être un problème de configuration de l'objet evaluant, je sais qu'avec le parseur msxml de microsoft il faut lui préciser qu'o travaille en xpath autrement on ne peut pas utiliser les fonction.
    Si ce n'est pas la DTD de ton xml complet c'est peut être aussi un problème de positionnement de départ
    en passant il y a plus propre que ton expression
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     /tv/channel[not(@id)]/display-name[1]

  8. #8
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut
    merci polymorphisme

  9. #9
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par Erwy Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     /tv/channel[not(@id)]/display-name[1]
    ca marché pas aussi

  10. #10
    Rédacteur

    Avatar de Erwy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2003
    Messages
    4 967
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 967
    Points : 10 927
    Points
    10 927
    Par défaut
    Est-ce que tu pourrais nous dire quel parseur ou bibliothèque tu utilise, cela permettrait, sinon de t'aider directement, peut être au moins de mieux t'orienter ?

  11. #11
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut
    enfin ca marché avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    /tv/channel[not(@id)]/display-name[1]
    j'ai changé le comptenu de l'arbre dom.

    -j'utilise libxml2

    merci pour tous

  12. #12
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 11
    Points
    11
    Par défaut
    le probleme persiste encore l'orsque dans l'arbre dom y a pas des noeuds qui verifie l'expression XPath
    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
     
          xpathRes = xmlXPathEvalExpression("/requete/channel[not(@id)]/display-name[1]", ctxt);
        printf("2\n");
            if (xpathRes == NULL) {
                fprintf(stderr, "Erreur sur l'expression XPath\n");
                //exit(-1);
            }
            printf("%d\n",xpathRes->nodesetval->nodeNr);
            if (xpathRes->type == XPATH_NODESET) {
                int i;
     
                for (i = 0; i < xpathRes->nodesetval->nodeNr; i++) {
                    xmlNodePtr n = xpathRes->nodesetval->nodeTab[i];
                    lenConCH=14+strlen((char*)n->children->content);
                    ch->lenCons=ch->lenCons+lenConCH;
                    //printf("malloc%d\n",i);
                    ch->TabCon[ch->nbrCon]=(char*)malloc(sizeof(char) *lenConCH);
                    strcpy((char*)ch->TabCon[ch->nbrCon],(const char*)"display-name=");
                    strcat((char*)ch->TabCon[ch->nbrCon],(char*)n->children->content);
                    ch->nbrCon=ch->nbrCon+1;
                }
            }
    avec ce code l'orsque l'arbre dom ne contient pas des noeuds qui verifis l'expression XPath, on arrive jusqu a la boucle for, donc pb causé par "xpathRes->nodesetval->nodeNr"

Discussions similaires

  1. detecter l'absence ou la présence d'une phrase
    Par gastoncs dans le forum VB.NET
    Réponses: 3
    Dernier message: 19/01/2012, 19h40
  2. [Xpath] Sélection des noeuds dont un attribut
    Par toxine dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 29/01/2007, 14h22
  3. [xpath] Requête sur le nom des attributs sans casse
    Par fedfil dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 30/01/2006, 10h58
  4. [XSL][XPATH] recopier les attributs d un élément mais pas le
    Par Triangle dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 26/08/2005, 16h07
  5. [SynEdit][HighLighter] Detection d'attributs
    Par Mercilius dans le forum Composants VCL
    Réponses: 3
    Dernier message: 12/11/2003, 16h28

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