谁能详细告诉我 libxml2 库中的 xmlHashScan 函数? [英] Can anyone tell me in detail about xmlHashScan function in the libxml2 library?

查看:38
本文介绍了谁能详细告诉我 libxml2 库中的 xmlHashScan 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能详细告诉我 libxml2 库中的 xmlHashScan 函数?

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

推荐答案

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

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

//假设 libxml2 位于/usr/local/include 和/usr/local/lib

// 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]

//其中 th.c 如下:

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

这篇关于谁能详细告诉我 libxml2 库中的 xmlHashScan 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆