• [^] # testé et

    Posté par . En réponse au message XPath : comment formuler cette requête ?. Évalué à 2.

    c'est moi ça marche.
    J'ai pris cet exemple de la doc : http://www.xmlsoft.org/examples/index.html#xpath1.c(...)

    Modifier un peu le code de print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) pour afficher le contenu des attributs.

    Et avec ton fichier :
    [alex@zzz ~/xpath]$ ./xpath1 test.xml "//package[contains(./depends/text(),'libxml2')]/@name"
    Result (2 nodes):
    = attribute "name"
    value="fpack2"

    [alex@zzz ~/xpath]$ ./xpath1 test.xml "//package[contains(./depends/text(),'base')]/@name"
    Result (3 nodes):
    = attribute "name"
    value="hdparm"
    = attribute "name"
    value="fpack2"

    D'ailleurs attention aux effet parasite : si tu cherche le package "base" alors qu'un package s'appelle "xmlbase" -> tu match alors que tu ne devrais pas.

    Code en peluche :

    } else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
    // tout pareil
    } else if(nodes->nodeTab[i]->type == XML_ATTRIBUTE_NODE) {
    cur = nodes->nodeTab[i];
    xmlNodePtr parent= cur->parent;
    fprintf(output, "= attribute \"%s\"\n", cur->name);
    fprintf(output, " value=\"%s\"\n", xmlGetProp(parent, "name"));
    } else {
    // tout pareil
    }