本文主要是介绍libxml2 获取每个节点的值,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <libxml2/libxml/xmlmemory.h> #include <libxml2/libxml/parser.h> static char nodesXml[30][30] = {0}; int initXml() { int i = 0; char line[200] = {0}; FILE *fp;//打开配置文件句柄 if((fp = fopen("xml.ini","r")) ==NULL) { fprintf(stderr, "open xml.ini error\n"); return -1; } while(fgets(line,200,fp)!=NULL) { Trim(line); strcpy(nodesXml[i],line); i++; } fclose(fp); return 0; } int parseXML(char* pXml,int length) { int i = 0; xmlDocPtr doc = xmlParseMemory(pXml, length); xmlNodePtr cur = xmlDocGetRootElement(doc); cur = cur->children; while ( cur != NULL) { xmlChar* key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); printf("【%s = %s】\n",nodesXml[i],key); xmlFree(key); cur = cur->next; i++; } }
这篇关于libxml2 获取每个节点的值的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!