#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++; } }