boost.property_tree
//made by davidsu33
//boost.property_tree是一個保存了多個屬性值的樹形數據結構
//boost.property_tree可以解析xml ini json和info四種格式的文本
#include
#include
#include
#include
#include
#include
using namespace std;
void putline(const char * str)
{
cout<("conf.theme");
int guiID = pt.get("conf.gui");
//int id = pt.get_value();
assert(guiID == 1);
//不存在屬性返回默認值
int def = pt.get("conf.no", 100000);
assert(def = 100000);
BOOST_AUTO(childs2, pt.get_child("conf.urls"));
PTree childs = pt.get_child("conf.urls");
//???
//int count = pt.count("urls");
//assert(count == 3);
//讀取多子節點的數據
BOOST_AUTO(it, childs.begin());
BOOST_AUTO(iend, childs.end());
for (;
it != iend; ++it)
{
//迭代器指向ptree的value_type,
//它的second成員是子節點自身
//cout<second.get_value()<second.data()<(""); //讀取XML聲明
BOOST_ASSERT(pt.get("conf.gui..lib") == "QT");
BOOST_ASSERT(pt.get("conf.theme..id") == 1002);
BOOST_ASSERT(pt.get("conf.") == "this is conf comment");
//貌似不支持CDATA,測試未通過
//std::string xmltext = pt.get("conf.");
//BOOST_ASSERT(pt.get("conf.") == "字符數據-character data");
}
int _tmain(int argc, _TCHAR* argv[])
{
parse_xml();
getchar();
return 0;
}