谁能告诉我有关libxml2库中xmlHashScan函数的详细信息?

时间:2009-11-06 09:39:29

标签: xml parsing

有人能详细告诉我libxml2库中的xmlHashScan功能吗?

2 个答案:

答案 0 :(得分:0)

//这是一个我拼凑在一起为自己澄清的例子:

//假设libxml2位于/ usr / local / include和/ 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]

//其中th.c如下:

#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();
}

答案 1 :(得分:-1)

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