1 Star 0 Fork 26

方斌斌1990/fastxml

forked from Josin/fastxml 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.c 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
liqiongfan 提交于 2019-07-18 10:14 . 增加XML属性快捷操作宏
/**
* Copyright @2019 Josin All Rights Reserved.
* Author: Josin
* Email : xeapplee@gmail.com
*
* Hello, This is the fast xml's parsing example
* To simplify the coding, the thing you want to do
* is to add some macros, Let's have a try.
*/
#include <stdio.h>
#include <xml_demo.h>
int main(int argc, char *argv[])
{
char *xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\" author=\"Josin\" ?>\n"
"<!--Hello This is the comments-->\n"
"<info>\n"
" <name id=\"11\" ppid=\"228\"><![CDATA[Josin]]></name>\n"
" <address>Hunan</address>\n"
"</info>";
CXML *xml = new_cxml_from_string(xml_str, strlen(xml_str));
if ( !xml ) {
printf("Your xml format is wrong.");
trash_cxml(xml);
return 0;
}
CXML_root *root = NEW_CXML_root_FROM_DATA(xml->data);
printf("Root name: %s\n", root->info->key);
CXML_info *info = NEW_CXML_info_FROM_DATA(root->info->val);
printf("%s: %s\n", info->name->key, (char *)info->name->val);
printf("%s: %s\n", info->addr->key, (char *)info->addr->val);
CXML_name *nameAttrs = NEW_CXML_name_FROM_ATTR(info->name->attrs);
printf("%s:%s\n", nameAttrs->id->key, nameAttrs->id->val);
printf("%s:%s\n", nameAttrs->ppid->key, nameAttrs->ppid->val);
TRASH_CXML_name(nameAttrs);
TRASH_CXML_info(info);
TRASH_CXML_root(root);
trash_cxml(xml);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/fangbinbin1990/fastxml.git
git@gitee.com:fangbinbin1990/fastxml.git
fangbinbin1990
fastxml
fastxml
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385