用于以XML格式存储设置的C++库

JWo*_*ood 5 c++ xml winapi stl

在我开始使用自己的设置库编写之前,我会尝试找到现有的库.我用Google搜索并找到了很多C#或MFC,但没有使用普通的C++/STL.我想要一些允许通过键访问的东西,例如:

mySettings["Root"]["Subsection"]["Value"].Value
Run Code Online (Sandbox Code Playgroud)

或类似的规定.是否有任何东西可以提供XML文件的那种接口,或者我将不得不自己滚动?

谢谢,J

seh*_*ehe 7

有TinyXML和pugixml

PugiXML确实有XPath支持


Ral*_*alf 5

Boost属性树是一个这样的库,但你必须考虑是否要为此目的引入boost.它适用于简单的配置属性,如示例中所示,但我记得做一些更复杂的事情花了我一点时间才能做到正确:

以下代码取自文档:

// Create an empty property tree object
using boost::property_tree::ptree;
ptree pt;

// Load the XML file into the property tree. If reading fails
// (cannot open file, parse error), an exception is thrown.
read_xml(filename, pt);

// Get the filename and store it in the m_file variable.
// Note that we construct the path to the value by separating
// the individual keys with dots. If dots appear in the keys,
// a path type with a different separator can be used.
// If the debug.filename key is not found, an exception is thrown.
m_file = pt.get<std::string>("debug.filename");
Run Code Online (Sandbox Code Playgroud)