C語言實現(xiàn)xml構(gòu)造解析器
純C實現(xiàn)xml構(gòu)造解析器,所有實現(xiàn)只有一個.c一個.h文件組成,簡單易用,易于擴展。
#include <string.h> #include <stdio.h> #include <stdlib.h> #include "sxml.h" #define LUA_SCRIPT "function fun()\n\ int a;\n\ a = 10;\n\ return a;\n\ end" int main() { sxml_file_info_t* info; char* tmp; const char* pstr; int line=1; char buff[128]={0}; sxml_doc_t* parser=NULL; sxml_doc_t* doc = sxml_doc_new("a.xml","1.0","GB2312"); sxml_node_t* node = sxml_node_new("root"); sxml_attr_t* attr = sxml_attr_new("age","25"); sxml_node_t* subnode = sxml_node_new("score"); sxml_node_t* rawdata = sxml_rawdata_new(NULL,"hello world!",strlen("hello world!")); sxml_node_t* rawdata2 = sxml_rawdata_new(NULL,"hello world!",strlen("hello world!")); sxml_node_t* rawdata3 = sxml_rawdata_new(NULL,"hello world!",strlen("hello world!")); sxml_node_t* rawdata4 = sxml_rawdata_new("raw","rawdata",strlen("rawdata")); sxml_node_t* rawdata5 = sxml_rawdata_new("lua",LUA_SCRIPT,strlen(LUA_SCRIPT)); sxml_node_t* innertext = sxml_innertext_new("內(nèi)部字符串"); sxml_node_t* comment = sxml_comment_new("注釋"); sxml_node_t* empty = sxml_empty_new("empty"); sxml_add_attr2node(node,attr); attr = sxml_attr_new("sex","man"); sxml_add_attr2node(node,attr); attr = sxml_attr_new("語文","95"); sxml_add_attr2node(subnode,attr); attr = sxml_attr_new("數(shù)學(xué)","100"); sxml_add_attr2node(subnode,attr); attr = sxml_attr_new("英語","98"); sxml_add_attr2node(subnode,attr); sxml_add_subnode2node(node,subnode); sxml_add_subnode2node(node,rawdata); sxml_add_subnode2node(node,rawdata2); sxml_add_subnode2node(node,rawdata3); sxml_add_subnode2node(node,rawdata4); sxml_add_subnode2node(node,rawdata5); sxml_add_subnode2node(node,innertext); sxml_add_subnode2node(node,comment); sxml_add_subnode2node(node,empty); sxml_add_node2doc(doc,node); //printf("%s\n",sxml_doc_print_buffered(doc,16)); tmp = sxml_doc_print(doc); pstr = tmp; printf("%s\n", tmp); while((pstr = skip_line(pstr)))line++; printf("\n\n%d\n\n", line); //printf("\n\n%s\n\n",check_skip("<?xml version=\"1.0\" encoding=\"GB2312\"?>","<?xml version=\\\"")?"YES":"NO"); //copy_until(buff,"<?xml version=\"1.0\" encoding=\"GB2312\"?>","\" "); //printf("\n\n%s\n\n",buff); //sxml_save(doc); sxml_doc_free(doc); doc = NULL; free(tmp); //printf("aaaa...................\n"); //getchar(); parser = sxml_parse("a.xml"); //tmp = sxml_doc_print(parser);//有問題,內(nèi)存越界 tmp = sxml_doc_print_buffered(parser,16); printf("%s\n", tmp); free(tmp); sxml_save2file(parser,"b.xml"); sxml_doc_free(parser); return 0; }
上一篇:C++的template模板中class與typename關(guān)鍵字的區(qū)別分析
欄 目:C語言
下一篇:C語言之實現(xiàn)控制臺光標隨意移動的實例代碼
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2199.html
您可能感興趣的文章
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用函數(shù)刪除字符
- 04-02c語言的正則匹配函數(shù) c語言正則表達式函數(shù)庫
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對數(shù)怎么表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段函數(shù)
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排序法函數(shù)
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段函數(shù)
- 04-02C語言中怎么打出三角函數(shù) c語言中怎么打出三角函數(shù)的值
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求階乘


閱讀排行
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機閱讀
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 04-02jquery與jsp,用jquery
- 01-10C#中split用法實例總結(jié)
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢data目錄下的sessions文件夾有什