xref: /MusicPlayer2/MusicPlayer2/TinyXml2Helper.h (revision 26cefa3ce191eaff4754c23aa55c7bab36bd518b)
1 #pragma once
2 #include "tinyxml2/tinyxml2.h"
3 
4 class CTinyXml2Helper
5 {
6 public:
7 
8     //从文件读取XML内容
9     static bool LoadXmlFile(tinyxml2::XMLDocument& doc, const wchar_t* file_path);
10 
11     //遍历一个XML节点
12     //fun: 一个函数对象,遍历到一个节点时被调用
13     static void IterateChildNode(tinyxml2::XMLElement* ele, std::function<void(tinyxml2::XMLElement*)> fun);
14 
15     //获取一个节点的属性(返回值不会为空指针,如果找不到则返回空字符串)
16     static const char* ElementAttribute(tinyxml2::XMLElement* ele, const char* attr);
17 
18     //获取一个节点的名称(返回值不会为空指针,如果找不到则返回空字符串)
19     static const char* ElementName(tinyxml2::XMLElement* ele);
20 
21     //获取一个节点的文本(返回值不会为空指针,如果找不到则返回空字符串)
22     static const char* ElementText(tinyxml2::XMLElement* ele);
23 
24     static bool StringToBool(const char* str);
25 
26     static void GetElementAttributeBool(tinyxml2::XMLElement* ele, const char* attr, bool& value);
27     static void GetElementAttributeInt(tinyxml2::XMLElement* ele, const char* attr, int& value);
28 };
29