轻量级C语言实现的xml解析库minixml

前端之家收集整理的这篇文章主要介绍了轻量级C语言实现的xml解析库minixml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1下载:http://www.msweet.org/downloads.PHP?L+Z3

2说明:Mini-XML是一个小型的开源的XML解析器,采用 C 语言开发。该解析器最大的特点就是小型、无须依赖其他类库,只需要 GCC编译器和 make 程序即可编译,支持 UTF-8/UTF-16 编码。

Mini-XML支持读取UTF-8和UTF-16和UTF-8编码的XML文件和字符串写。数据存储在 链表树结构,保留XML数据的层次结构,并且没有预设的限制,可用内存维护任意元素名称属性属性值。

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

猜你在找的XML相关文章