分享內部基於libevent 和 levedb的小型數據庫wolfdb配置文件
<?xml version="1.0"?>
<wolf>
<dbs>
<node name="a">
<path>./data/</path>
</node>
<node name="b">
<path>./data/</path>
</node>
<node name="c">
<path>./data/</path>
</node>
</dbs>
<http>
<ip>0.0.0.0</ip>
<port>5111</port>
</http>
<socket>
<ip>127.0.0.1</ip>
<port>5678</port>
</socket>
</wolf>
xml 解析代碼段
void wolf_config::wolf_db_set() {
db db_item;
XMLDocument xmldoc;
xmldoc.LoadFile("wolf.xml");
XMLElement *wolf = xmldoc.RootElement();
XMLElement *dbs = wolf->FirstChildElement("dbs");
XMLElement *dbsChild = dbs->FirstChildElement();
const char* content;
while (dbsChild) {
dbs_number = dbs_number + 1;
const XMLAttribute *attributeOfDbs = dbsChild->FirstAttribute();
XMLElement *dbsChilds = dbsChild->FirstChildElement("path");
content = dbsChild->GetText();
dbsChild = dbsChild->NextSiblingElement();
string key = attributeOfDbs->Value();
db_item.name = key;
cout << attributeOfDbs->Value() << endl;
const char* contents;
while (dbsChilds) {
contents = dbsChilds->GetText();
dbsChilds = dbsChilds->NextSiblingElement();
db_item.path = contents;
this->db_family.insert(pair<string, db>(db_item.name, db_item));
}
}
dbs = dbs->NextSiblingElement();
return;
};