开发者

Can anyone tell me in detail about xmlHashScan function in the libxml2 library?

开发者 https://www.devze.com 2022-12-10 12:41 出处:网络
Can anyone tell me in detail about xmlHashScan function in t开发者_开发技巧he libxml2 library?// here is an example I cobbled together to clarify for myself:

Can anyone tell me in detail about xmlHashScan function in t开发者_开发技巧he libxml2 library?


// here is an example I cobbled together to clarify for myself:

// assume libxml2 is in /usr/local/include and /usr/local/lib

gcc -std=gnu99 -g3 -I/usr/local/include/libxml2 -c th.c
gcc -std=gnu99 -g3 -o th th.o -L/usr/local/lib -lxml2
./th

ht{foo} == FOO
ht{bar} == BAR
k/v == [bar,BAR]
k/v == [foo,FOO]

// where th.c is as follows:

#include <libxml/hash.h>

static void perEntry(void *payload, void *data, xmlChar *name) {
    char *fmt_psz = (char *) data;
    char *key_psz = (char *) name;
    char *value_psz = (char *) payload;

    printf(fmt_psz, key_psz, value_psz);
}

void testHash(void) {
    xmlHashTablePtr ht = xmlHashCreate(0);

    xmlHashAddEntry(ht, "foo", "FOO");
    xmlHashAddEntry(ht, "bar", "BAR");

    const xmlChar *f = xmlHashLookup(ht, "foo");
    const xmlChar *b = xmlHashLookup(ht, "bar");
    printf("ht{%s} == %s\n", "foo", f);
    printf("ht{%s} == %s\n", "bar", b);

    xmlHashScanner hsf = perEntry;
    xmlHashScan(ht, hsf, "k/v == [%s,%s]\n");

    xmlHashFree(ht, NULL);
}

int main(int argc, char *argv[]) {
    testHash();
}


Function: xmlHashScan

void    xmlHashScan         (xmlHashTablePtr table, 
                     xmlHashScanner f, 
                     void * data)

Scan the hash @table and applied @f to each value.
table:  the hash table
f:  the scanner function for items in the hash
data:   extra data passed to f
0

精彩评论

暂无评论...
验证码 换一张
取 消