pugixml
来源:互联网 发布:椒江淘宝摄影 编辑:程序博客网 时间:2024/05/12 14:03
使用pugixml库需要三个文件:pugiconfig.h/pugixml.h/pugixml.cpp,可直接从gugixml官网下载,将其加入工程,使用处包含头文件pugiconfig.h/pugixml.h即可。
#include <iostream>#include "pugiconfig.hpp"#include "pugixml.hpp"#include <string.h>#include <stdio.h>#include <stdlib.h>using namespace std;using namespace pugi;//读节点属性bool ReadXml(const char *xmlfile){xml_document doc;if(doc.load_file(xmlfile)){cout<<"....."<<endl;return false;}//input属性值xml_node form=doc.child("root").child("form");//得到根节点下的子节点string ip=form.attribute("ip").value();//得到属性值string port=form.attribute("port").value();//得到属性值string action=form.attribute("action").value();//得到属性值cout<<ip.data()<<endl;cout<<port.data()<<endl;cout<<action.data()<<endl;return true;}//遍历根节点下的字节点bool TravelXml(const char *xmlfile){xml_document doc;if(doc.load_file(xmlfile)){cout<<"load error"<<endl;return false;}xml_node form=doc.child("root").child("form");for(xml_node input=form.first_child();input;input=input.next_sibling()){string strname=input.attribute("name").value();cout<<"name="<<strname<<endl;if(!strname.empty()){string strvalue=input.attribute("value").value();cout<<"value="<<strvalue<<endl;}}return true;}//增加节点bool AppendXml(const char *xmlfile){xml_document doc;if(!doc.load_file(xmlfile)){cout<<"load error"<<endl;return false;}xml_node root=doc.child("root");root.append_child("wei");doc.save_file(xmlfile);return true;}//删除节点bool RemoveXml(const char *xmlfile){xml_document doc;if(!doc.load_file(xmlfile)){cout<<"load error"<<endl;return false;}xml_node root=doc.child("root");root.remove_child("wei");doc.save_file(xmlfile);return true;}int main(void){ReadXml("./example1.xml");//TravelXml("./example1.xml");//AppendXml("./example1.xml");//RemoveXml("./example1.xml");return 0;}
0 0
- pugixml
- pugixml简介
- pugixml简介
- pugixml简介
- pugixml,tinyxml
- pugixml 开篇
- pugixml简介
- pugixml操作
- pugixml库
- pugixml使用
- pugixml简单实用
- [转]pugixml简介
- pugixml使用教程
- pugixml工具简单介绍
- pugixml库的使用
- pugixml使用总结
- pugixml库的使用
- pugixml 1.8快速入门
- Apache反向代理结合Tomcat集群来实现负载均衡(三)、tomcat集群
- Java 中的 HashCode的作用?
- txt pdf 等浏览器不直接打开下载程序
- windows下gvim中删除行尾^M字符
- 兼容各浏览器的js加入收藏,设为首页代码
- pugixml
- Java 5.0多线程编程
- iOS编程中注意点
- 如何用PowerDesigner逆向工程导出ORACLE数据库表结构
- 如何设置backBarButtonItem的title和action
- Facebook强制要求下载Messenger
- 没有能力,就没有尊严!
- 求next数组代码
- windows7单机运行两个tomcat实例