linux (一) xml
原创
©著作权归作者所有:来自51CTO博客作者残月缺的原创作品,请联系作者获取转载授权,否则将追究法律责任
#include"stdio.h"
#include<libxml/parser.h>
#include<libxml/tree.h>
#include<libxml/xmlmemory.h>
int main()
{
xmlDocPtr doc;
xmlNodePtr cur,root,childcur;
xmlChar* key;
char* xmlfile = "xx1.xml";
doc = xmlParseFile(xmlfile);
if(doc == NULL)
{
fprintf(stderr,"not parserfile");
}
root = xmlDocGetRootElement(doc);
if(root == NULL)
{
fprintf(stderr,"not root");
xmlFreeDoc(doc);
}
if(xmlStrcmp(root->name,(const xmlChar*)"root"))
{
xmlFreeDoc(doc);
fprintf(stderr,"not root");
}
cur = root->xmlChildrenNode;
while(cur != NULL)
{
if(!xmlStrcmp(cur->name,(const xmlChar*)"datasource"))
{
key = xmlGetProp(cur,"name");
printf("%s\n",(char *)key);
childcur = cur->xmlChildrenNode;
while(childcur != NULL)
{
if(!xmlStrcmp(childcur->name,(const xmlChar*)"dataitem"))
{
key = xmlGetProp(childcur,"name");
printf("%s\n",(char*)key);
}
childcur = childcur->next;
}
}
cur = cur->next;
}
return 0;
}
gcc -g -I /usr/local/include/libxml2 -lxml2 xml.c -o xml
1 linux 读取xml。
2 gcc编译。
下一篇:gcc -I -L -l区别
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MybatisPlus基础Xml使用教程
MybatisPlus基础最全教程,里面包含操作的核心教程以及重点难点,很适合新手以及中高级开发学习
mybatis mybatisplus springboot -
linux学习(一)
linux系统部分学习。包括进程管理,文件管理的详解,以及环境变量,进程间通信,信号等的认识。
进程地址空间 文件系统 进程间通信 环境变量 信号