Pure C implements the XML construction parser, all implementations have only one. h file composition, easy to use, easy to expand.
#include <string.h> #include <stdio.h> #include <stdlib.h> #include "sxml.h" #define Lua_script "Fu
Nction 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("internal string");
sxml_node_t* comment = sxml_comment_new ("notes");
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 ("Language", "95");
Sxml_add_attr2node (SUBNODE,ATTR);
attr = Sxml_attr_new ("mathematics", "100");
Sxml_add_attr2node (SUBNODE,ATTR);
attr = Sxml_attr_new ("English", "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);//There is a problem, memory is out of bounds tmp = sxml_doc_print_buffered (parser,16);
printf ("%s\n", TMP);
Free (TMP);
Sxml_save2file (parser, "B.xml");
Sxml_doc_free (parser);
return 0;
}