tinyxml2解析XML文件
tinyxml2::XMLDocument xmlDoc;tinyxml2::XMLError error = xmlDoc.LoadFile(cfgFile.c_str());if (error != tinyxml2::XML_NO_ERROR) {throw ConfigurationFileNotFound("Configuration File is failed to open");}//解析文档// HOSTtinyxml2::XMLElement* root = xmlDoc.FirstChildElement("config")->FirstChildElement( "web");const char * contextStr = root->FirstChildElement("host")->GetText();hostConfig.host = contextStr;contextStr = root->FirstChildElement( "port" )->GetText();hostConfig.port = atoi( contextStr );// DBroot = xmlDoc.FirstChildElement("config")->FirstChildElement("db");contextStr = root->FirstChildElement("host")->GetText();dbConfig.host = contextStr;contextStr = root->FirstChildElement("port")->GetText();dbConfig.port = atoi( contextStr );contextStr = root->FirstChildElement("username")->GetText();dbConfig.username = contextStr;contextStr = root->FirstChildElement("password")->GetText();dbConfig.password = contextStr;// SFTProot = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "sftp" );contextStr = root->FirstChildElement( "host" )->GetText();sftpConfig.host = contextStr;contextStr = root->FirstChildElement("username")->GetText();sftpConfig.username = contextStr;contextStr = root->FirstChildElement("password")->GetText();sftpConfig.password = contextStr;contextStr = root->FirstChildElement("remote")->GetText();sftpConfig.remote= contextStr;contextStr = root->FirstChildElement("local")->GetText();sftpConfig.local = contextStr;// Pathroot = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "path" );resultPath = root->FirstChildElement( "result" )->GetText();reportPath = root->FirstChildElement( "report" )->GetText();// Resend Packroot = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "multipack" );multiPackResendConfig.timeout = atoi(root->FirstChildElement("timeout")->GetText());multiPackResendConfig.maxcount = atoi(root->FirstChildElement("maxcount")->GetText());root = xmlDoc.FirstChildElement( "config" )->FirstChildElement( "singlepack" );singlePackResendConfig.timeout = atoi(root->FirstChildElement("timeout")->GetText());singlePackResendConfig.maxcount = atoi(root->FirstChildElement("maxcount")->GetText());
下面是xml文件
<config><web><host>172.16.6.70</host><port>5055</port></web><db><host>172.16.6.78</host><port>5432</port><username>postgres</username><password>postgres</password><dbname>RemoteAssert</dbname></db><sftp><host>172.16.6.78</host><username>root</username><password>*********</password><remote>/opt</remote><local>/home/liujiayu/diagnosefile/cmdanddatafile</local></sftp><path><result>/home/liujiayu/diagnosefile/result</result><report>/home/liujiayu/diagnosefile/report</report></path><multipack><timeout>10</timeout><maxcount>3</maxcount></multipack><singlepack><timeout>3</timeout><maxcount>3</maxcount></singlepack>
</config>
tinyxml2解析XML文件相关推荐
- C++ 本地使用tinyxml2解析Xml文件
1.基本介绍 TinyXML2是一个开源.简单.小巧.高效的C++ XML解析器,它只有一个.h文件和一个.cpp文件组成,可以轻松集成到其它程序中.非常方便我们使用c++对xml进行处理. 可以读取 ...
- C++ 使用 TinyXml 解析 XML 文件
知乎 C++解析xml有什么好用的轮子? :https://www.zhihu.com/question/32046606 TinyXML-2 的 github地址和帮助文档:https://git ...
- 《转》 在C++中使用TinyXML2解析xml
读取和设置xml配置文件是最经常使用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,由于它的API接口和Java的十分类似.面向对象性非常好. TinyX ...
- TinyXML-2解析XML数据
声明 本文例子源自在C++中使用TinyXML2解析xml一文,其余部分来源于网络搜集,难免疏漏,敬请随意吐槽. XML以及JSON 什么是XML 根据Wikipedia-XML的说法: 可扩展标记语 ...
- (C++)将数据库文件导出XML文件以及解析XML文件生成数据库文件的处理方法
将数据库文件导出XML文件以及解析XML文件生成数据库文件的处理方法 思路:将数据库所有要导出的信息通过sql语句得到,存储到结构体中,然后将结构体的内容通过自定义的xml格式导出. 此方法使用的是T ...
- tinyxml2解析rss文件
参考资料:xml -> rss -> tinyxml -> regex xml:XML 教程 rss:RSS 教程 tinyxml2:TinyXML-2: TinyXML-2 reg ...
- python中利用lxml模块解析xml文件报错XMLSyntaxError: Opening and ending tag mismatch
今天在代码中第一次使用lxml解析xml文件时出错了, XMLSyntaxError: Opening and ending tag mismatch: keyEffectiveDate line 2 ...
- java xml中的冒号_Java jdom解析xml文件带冒号的属性
Java jdom解析xml文件带冒号的属性 如果xml文件解析带了冒号的属性,一般都是要特别处理,这里是命名空间,N年前遇到过一次忘记记录,后来也忘了,这次再记录下. 解决了,记录下,分享给大家,百 ...
- XML专题:使用NSXMLParser解析xml文件
使用NSXMLParser解析xml文件 1. 设置委托对象,开始解析 NSXMLParser *parser = [[NSXMLParser alloc] initWithData:dat ...
最新文章
- python绘制坐标图_Python绘制主次坐标图
- maven-eclipse 中index.html页面乱码
- 杀软厂商开源--从此走向平台化?
- how can you save more space at home?
- CF-558E(E. A Simple Task)
- Token的解密和加密
- Android自定义控件学习(六)-------使视图互动
- vsftp 配置参数详解
- C语言程序设计(第三版)何钦铭著 习题5-7
- libaio.so.1 is needed by MySQL-server-5.5.48-1.linux2.6.i386
- matlab如何设全局变量,请问MATLAB中如何修改全局变量
- 杀毒软件哪个好?2011年12月(第六次)VB100认证结果出炉
- R语言读取(加载)txt格式数据为dataframe、按照指定字段(数据列)对dataframe进行升序排序(ascending)、返回行索引的位置向量
- 分层图解决的一些最短路问题
- InputStreamReader乱码
- 用VUE实现注册页(短信验证码登录)
- Mysql关联查询的几种方式(详解)
- 在线详情页设计,素材免扣直接用!
- AVX 指令集并行技术优化中值滤波
- 完整过程解决 ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: NO)