linux下libxml2应用--生成一个tree并且保存为xml文件
2007-11-02 20:44
561 查看
导读:
#include
#include
#include
#define BUF 200
// 该函数生成tree并且将tree的内容保存为xml格式以及将tree的内容转换成字符串带出来
int MakeXmldata(char* cxmlbuff)
{
xmlDocPtr doc = NULL; // document pointer
xmlNodePtr root_node = NULL, node1 = NULL, node2 = NULL; // node pointers
// Creates a new document, a node and set it as a root node
doc = xmlNewDoc(BAD_CAST"1.0");
root_node = xmlNewNode(NULL, BAD_CAST"root");
xmlDocSetRootElement(doc, root_node);
// creates a new node, which is "attached" as child node of root_node node.
node1 = xmlNewChild(root_node, NULL, BAD_CAST"node1", BAD_CAST"node-1");
// xmlNewProp() creates attributes, which is "attached" to an node.
node2 = xmlNewChild(root_node, NULL, BAD_CAST"node2", BAD_CAST"node-2");
// 给节点添加属性说明
xmlNewProp(node2, BAD_CAST"attribute", BAD_CAST"yes");
// 用另一种方法生成节点
node2 = xmlNewText(BAD_CAST"node-3");
xmlAddChild(node1, node2);
// Dumping document to stdio or file
xmlAddChild(root_node, node1);
// 将生成的tree保存为xml格式的文件
xmlSaveFormatFileEnc("xmltest.xml", doc, "UTF-8", 1);
// 将tree的内容转化为字符串
#include
#include
#include
#define BUF 200
// 该函数生成tree并且将tree的内容保存为xml格式以及将tree的内容转换成字符串带出来
int MakeXmldata(char* cxmlbuff)
{
xmlDocPtr doc = NULL; // document pointer
xmlNodePtr root_node = NULL, node1 = NULL, node2 = NULL; // node pointers
// Creates a new document, a node and set it as a root node
doc = xmlNewDoc(BAD_CAST"1.0");
root_node = xmlNewNode(NULL, BAD_CAST"root");
xmlDocSetRootElement(doc, root_node);
// creates a new node, which is "attached" as child node of root_node node.
node1 = xmlNewChild(root_node, NULL, BAD_CAST"node1", BAD_CAST"node-1");
// xmlNewProp() creates attributes, which is "attached" to an node.
node2 = xmlNewChild(root_node, NULL, BAD_CAST"node2", BAD_CAST"node-2");
// 给节点添加属性说明
xmlNewProp(node2, BAD_CAST"attribute", BAD_CAST"yes");
// 用另一种方法生成节点
node2 = xmlNewText(BAD_CAST"node-3");
xmlAddChild(node1, node2);
// Dumping document to stdio or file
xmlAddChild(root_node, node1);
// 将生成的tree保存为xml格式的文件
xmlSaveFormatFileEnc("xmltest.xml", doc, "UTF-8", 1);
// 将tree的内容转化为字符串
相关文章推荐
- 记一次项目经历——linux环境下使用libxml2实现xml文件的生成与解析
- Python:在Linux下创建一个脚本并且自动修改权限,可以选择路径。批量生成脚本 。
- asp.net上传的图片保存到文件夹下,并且生成缩略图
- java生成一个XML文件,并且将该文件压缩成ZIP格式后再写到硬盘上
- Hibernate保存记录时遇到的一个问题----evitic,not-null配置及主键生成策略
- [Linux目录文件]综合应用--使用时间信息生成目录和文件
- 一个带采集远程文章内容,保存图片,生成文件等完整的采集功能
- linux下如何添加一个用户并且让用户获得root权限
- Linux手机DIY.Shell应用扩展二.自动生成播放列表(E680系列)
- Java 生成 XML文件应用示例
- 利用线性布局和相对布局实现一个简单的页面并且使应用支持国际化语言
- 生成全排列---reflect包的一个应用
- Linux系统下生成一个指定大小的文件和空间预留
- Linux下让一个普通用户并且获得root权限
- linux应用项目(二)摄像头(2)从零写一个V4L2虚拟摄像头驱动之详细分析
- Linux手机DIY.Shell应用扩展二.自动生成播放列表(E680系列)
- 一个获取手机应用并且按照安装的最新更新时间排序的demo
- 1.django学习:安装django并且部署一个应用
- linux下如何添加一个用户并且让用户获得root权限
- 一个在linux下生成bmp程序