相关疑难解决方法(0)

名称空间和xpath的libxml2错误

我在这里粘贴一些代码,使用gcc file.c -lxml2编译没有警告,假设你的系统中安装了libxml2.

#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <assert.h>
#include <libxml/tree.h>
#include <libxml/xpathInternals.h>

xmlDocPtr
getdoc (char *docname) {
    xmlDocPtr doc;
    doc = xmlParseFile(docname);

    if (doc == NULL ) {
        fprintf(stderr,"Document not parsed successfully. \n");
        return NULL;
    }

    return doc;
}

xmlXPathObjectPtr
getnodeset (xmlDocPtr doc, xmlChar *xpath){

    xmlXPathContextPtr context;
    xmlXPathObjectPtr result;

    context = xmlXPathNewContext(doc);
    if (context == NULL) {
        printf("Error in xmlXPathNewContext\n");
        return NULL;
    }

    if(xmlXPathRegisterNs(context,  BAD_CAST "new", BAD_CAST "http://www.example.com/new") != 0) {
        fprintf(stderr,"Error: unable to register NS with prefix");
        return …
Run Code Online (Sandbox Code Playgroud)

c xml xpath namespaces libxml2

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

libxml2 ×1

namespaces ×1

xml ×1

xpath ×1