Boost: property_tree-Old-blog
Boost: property_tree
Property_tree is a tree data structure that stores multiple attribute values. You can access attributes of any node in a simple way like a path, and each node can traverse subnodes in a similar STL style.
Property_treeEspecially suitable for application configuration data processingYou can parse text data in four formats: xml, ini, json, and info, which can ease your development and configuration management.
Take XML as an example:
1
2 /**
3 * Build Success By VC ++ 2010
4 *
5 * boost: property_tree
6 *
7 * copyright (C) 2010, liya
8 */
9
10/** Example XML
11 *
12 * <app>
13 * <version> 1.0.0.1 </version>
14 * <theme> blue </theme>
15 * <about>
16 * http://www.xyz.com
17 * <email> support@xyz.com </email>
18 * <content> coryright (C) xyz.com 2000-2010 </content>
19 * </about>
20 * </app>
21 */
22
23 # include <iostream>
24 # include <string>
25 # include <boost/property_tree/ptree. hpp>
26 # include <boost/property_tree/xml_parser.hpp>
27
28 using namespace std;
29 using namespace boost: property_tree;
30
31 void CreateConfig (string filename)
32 {
33 ptree pt;
34 read_xml (filename, pt );
35
36 pt. put ("app. version", "1.0.0.1 ");
37 pt. put ("app. theme", "blue ");
38 pt. put ("app. about. url", "http://www.xyz.com ");
39 pt. put ("app. about. email", "support@xyz.com ");
40 pt. put ("app. about. content", "coryright (C) xyz.com 2000-2010 ");
41
42 write_xml (filename, pt );
43}
44
45 int main (int argc, char * argv [])
46 {
47 CreateConfig (string ("config. xml"); // the config. xml file must exist, but can be empty.
48
49 return 0;
50}
51
Property_tree is a tree data structure that stores multiple attribute values. You can access attributes of any node in a simple way like a path, and each node can traverse subnodes in a similar STL style.
Property_treeEspecially suitable for application configuration data processingYou can parse text data in four formats: xml, ini, json, and info, which can ease your development and configuration management.
Take XML as an example:
1
2 /**
3 * Build Success By VC ++ 2010
4 *
5 * boost: property_tree
6 *
7 * copyright (C) 2010, liya
8 */
9
10/** Example XML
11 *
12 * <app>
13 * <version> 1.0.0.1 </version>
14 * <theme> blue </theme>
15 * <about>
16 * http://www.xyz.com
17 * <email> support@xyz.com </email>
18 * <content> coryright (C) xyz.com 2000-2010 </content>
19 * </about>
20 * </app>
21 */
22
23 # include <iostream>
24 # include <string>
25 # include <boost/property_tree/ptree. hpp>
26 # include <boost/property_tree/xml_parser.hpp>
27
28 using namespace std;
29 using namespace boost: property_tree;
30
31 void CreateConfig (string filename)
32 {
33 ptree pt;
34 read_xml (filename, pt );
35
36 pt. put ("app. version", "1.0.0.1 ");
37 pt. put ("app. theme", "blue ");
38 pt. put ("app. about. url", "http://www.xyz.com ");
39 pt. put ("app. about. email", "support@xyz.com ");
40 pt. put ("app. about. content", "coryright (C) xyz.com 2000-2010 ");
41
42 write_xml (filename, pt );
43}
44
45 int main (int argc, char * argv [])
46 {
47 CreateConfig (string ("config. xml"); // the config. xml file must exist, but can be empty.
48
49 return 0;
50}
51