TinyXml解析配置文件
TinyXml to parse conf file
我正在尝试实现如何使用TinyXML库。
我必须解析这个配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<Client>
<port num = "20035">
<server_addr ip="127.0.0.1">
<AV_list>
<AV>
<AVNAME>BitDefender</AVNAME>>
<AVPATH> C:Program FilesCommon FilesBitDefenderBitDefender Threat Scannerav64bit_26308bdc.exe </AVPATH>
<AVMASK>0x80000000</AVMASK>
<AVCOMMANDLINE> %avpath% log=%avlog% %scanpath% </AVCOMMANDLINE>
<AVREGEX>(%scanpath%.*?)+(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,4})+(.+[a-zA-Z_])</AVREGEX>
<AVLOG>C:logbd_log.txt</AVLOG>
</AV>
</AV_list>
</Client>
和c++代码
#include "stdafx.h"
#include "iostream"
#include "tinyxml.h"
int main(int argc, char* argv[])
{
TiXmlDocument doc( "D:\client_conf.xml" );
bool loadOkay = doc.LoadFile();
if ( loadOkay )
printf("Yes n");
else
printf("No n");
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
TiXmlText* pText;
TiXmlHandle hRoot(0);
pElem = hDoc.FirstChildElement().Element();
if (!pElem)
printf("error element");
hRoot = TiXmlHandle(pElem);
pElem = hRoot.FirstChild("server_addr").Element();
const char* info = pElem->Attribute("ip");
printf( "%s n", info);
pElem = hRoot.FirstChild("port").Element();
info = pElem->Attribute("num");
printf( "%s n", info);
system("pause");
return 0;
}
现在我可以得到前两个参数,但不知道如何达到"AV_list"块。任何帮助都将不胜感激。(:
请看一下TinyXml文档。您的朋友是TiXmlNode类引用。您也可以在TiXmlElements上使用大多数Node函数。您已经使用了FirstChild()函数来获取元素的第一个子元素;使用NextSibling()函数遍历所有元素。您也可以使用NextSiblingElement()函数直接获取元素。
另一个更复杂的解决方案是使用XPath从xml文件中检索元素。TinyXPath是建立在TinyXML之上的。它需要一些XPath知识,但可能是值得的。(XPath标准)
相关文章:
- 无法找到/读取配置文件.conf-FileIOException
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 一种在C++中读取TXT配置文件的简单方法
- FFMPEG配置文件级别id大小无效
- 配置文件解析器仅返回以前的值
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- Boost program_options将多个配置文件解析结果存储到一个parsed_options中
- Windows 后台服务(系统配置文件)无法使用 C++ 访问 win 10 上的用户 appData 文件夹?
- 我应该如何获取配置文件的绝对路径与 Windows .exe一起发布?
- JPG-如何从ICC配置文件部分APP2读取/提取数据
- 检测到 Conan 配置文件设置与 CMake 之间的编译器版本不匹配
- boost::p rogram_options 配置文件格式
- 如何在Boost::program_options配置文件中为非字符串的自定义选项值类型处理空格
- 如何在 Boost Program_Options 中使用命令行和分层配置文件的选项
- 如何将不可编译的配置文件添加到QT工程中?
- OpenGL不能在核心配置文件中使用glVertexAttrib进行绘制
- 错误 VSP1011:无法获取调试信息.与 /配置文件链接器开关链接
- 解析程序配置文件
- 提升program_option配置文件的不区分大小写的解析
- TinyXml解析配置文件