1下载:http://www.msweet.org/downloads.PHP?L+Z3
2说明:Mini-XML是一个小型的开源的XML解析器,采用 C 语言开发。该解析器最大的特点就是小型、无须依赖其他类库,只需要 GCC编译器和 make 程序即可编译,支持 UTF-8/UTF-16 编码。
3编译 ./configure--enable-threads=no(使其不依赖于pthread)
make
(静态包:ar rv libmxml.a mxml-attr.o mxml-entity.o mxml-file.o mxml-get.o mxml-index.o mxml-node.o mxml-search.o mxml-set.o mxmldoc.o mxml-private.o mxml-string.o)
4用法
<?xml version="1.0" encoding="gb2312" ?> <note year="55" date="33" month="22"> <id>5000</id> <password>FE-D0-18-00</password> </note>
#include<mxml.h> #include<string.h> #include<stdio.h> #include<stdlib.h> int main() { FILE *fp; mxml_node_t *tree,*node; fp = fopen("debug_settings.xml","r"); tree = mxmlLoadFile(NULL,fp,MXML_TEXT_CALLBACK); fclose(fp); mxml_node_t *id,*password; node = mxmlFindElement(tree,tree,"note",NULL,MXML_DESCEND); printf(" year:%s \n",mxmlElementGetAttr(node,"year")); printf(" date:%s \n","date")); printf(" month:%s \n","month")); id = mxmlFindElement(node,"id",MXML_DESCEND); printf("[%s}\n",id->child->value.text.string); password = mxmlFindElement(node,"password",MXML_DESCEND); printf("[%s]\n",password->child->value.text.string); mxmlDelete(tree); return 0 ; }