/
test_xml.cpp
68 lines (52 loc) · 2.04 KB
/
test_xml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "MQueue/parse_xml.h"
#include <iostream>
using std::cout;
using std::endl;
int main() {
ParseXmlObj myXml("../config/testXml.xml");
vector<map<string, string> > result_array = myXml.GetChildDataArray("Config.Server.Connection");
for (auto key_value_map : result_array) {
for (auto the_pair : key_value_map) {
cout << the_pair.first << "---" << the_pair.second << endl;
}
}
result_array = myXml.GetChildDataArray("Config.Client.Connection");
for (auto key_value_map : result_array) {
for (auto the_pair : key_value_map) {
cout << the_pair.first << "---" << the_pair.second << endl;
}
}
cout << "=========" << endl;
cout << myXml.GetChildData("hello.MysqlConnection.IP") << endl;
cout << "=========" << endl;
map<string, string> key_value_map = myXml.GetChildDataMap("hello.MysqlConnection");
for (auto the_pair : key_value_map) {
cout << the_pair.first << "---" << the_pair.second << endl;
}
cout << "+++++++++" << endl;
cout << myXml.GetAttr("errors.error", "id") << endl;
cout << "+++++++++" << endl;
vector<string> attr_vec = myXml.GetAttrArray("errors", "id");
for (auto i : attr_vec) {
cout << i << endl;
}
cout << myXml.GetAttrByAttr("errors", "id", "DB_ERROR_EXECUTE", "value") << endl;
//==================== put ====================
myXml.PutChildData("testPut", "testPut");
myXml.PutChildData("testPut2", "testPut2");
map<string, string> my_map;
my_map.insert(make_pair("IP","0.0.0.1"));
my_map.insert(make_pair("Port","1"));
my_map.insert(make_pair("max_con","1"));
myXml.PutChildDataMap("hello.TestConnection", my_map);
myXml.PutAttr("errors.error", "test", "ttttt");
cout << myXml.GetAttrByAttr("errors", "id", "DB_ERROR_EXECUTE","value") << endl;
map<string, string> other_map;
other_map.insert(make_pair("id", "iiiii"));
other_map.insert(make_pair("value", "000"));
other_map.insert(make_pair("prompt", "ppppp"));
other_map.insert(make_pair("msg", "mmmm"));
myXml.AddLineByAttr("errors.error", other_map);
myXml.SaveConfig();
return 0;
}