Samchon Framework for CPP  1.0.0
main.cpp
1 #include <iostream>
2 #include <vector>
3 #include <string>
4 
5 #include <samchon/library/XML.hpp>
6 
7 #ifdef _WIN64
8 # ifdef _DEBUG
9 # pragma comment(lib, "x64/Debug/SamchonFramework.lib")
10 # else
11 # pragma comment(lib, "x64/Release/SamchonFramework.lib")
12 # endif
13 #else
14 # ifdef _DEBUG
15 # pragma comment(lib, "Debug/SamchonFramework.lib")
16 # else
17 # pragma comment(lib, "Release/SamchonFramework.lib")
18 # endif
19 #endif
20 
21 using namespace std;
22 using namespace samchon::library;
23 
24 struct Member
25 {
26  string id;
27  string name;
28  int age;
29  int grade;
30 
31  auto toXML() const -> shared_ptr<XML>
32  {
33  shared_ptr<XML> xml(new XML());
34  xml->setTag("member");
35  xml->setProperty("id", id);
36  xml->setProperty("name", name);
37  xml->setProperty("age", age);
38  xml->setProperty("grade", grade);
39 
40  return xml;
41  };
42 };
43 
44 void main()
45 {
46  //DECLARE An XML WITH MEMBER_ARRAY TAG
47  shared_ptr<XML> xml(new XML());
48  xml->setTag("memberArray");
49 
50  //ADD MEMBER(S) TO XML
51  vector<struct Member> memberArray =
52  {
53  {"samchon", "Jeongho Nam", 27, 1},
54  {"gkyu", "Kwangkyu Ko", 25, 1},
55  {"guest", "John Doe", 99, 4}
56  };
57  for(size_t i = 0; i < memberArray.size(); i++)
58  xml->push_back( memberArray[i].toXML() );
59 
60  //ADD FILE_LIST BY STRING DIRECTLY
61  xml->push_back
62  (
63  string("") +
64  "<fileList>\n" +
65  "<file extension='pdf' name='API' />" +
66  "<file extension='pdf' name='Guidance+For+Developer'>Damaged</file>" +
67  "<file extension='docx' name='Resume' />" +
68  "<file extension='jpg' name='My+House' />" +
69  "<file extension='xlsx' name='Grades' />" +
70  "</fileList>"
71  );
72 
73  cout << "-----------------------------------------------------------------" << endl;
74  cout << " Get Properties And Values" << endl;
75  cout << "-----------------------------------------------------------------" << endl;
76  cout << "Age of 2nd member: " << xml->get("member")->at(1)->getProperty<int>("age") << endl;
77  cout << "Age of 1st member: " << xml->get("member")->at(0)->getProperty("id") << endl << endl;
78 
79  cout << "File name and extension of 5th: "
80  << xml->get("fileList")->at(0)->get("file")->at(4)->getProperty("name") << "."
81  << xml->get("fileList")->at(0)->get("file")->at(4)->getProperty("extension") << endl;
82  cout << "Value of 2nd file: " << xml->get("fileList")->at(0)->get("file")->at(1)->getValue() << endl << endl;
83 
84  cout << "-----------------------------------------------------------------" << endl;
85  cout << " XML to String: " << endl;
86  cout << "-----------------------------------------------------------------" << endl;
87  cout << xml->toString() << endl;
88 
89  system("pause");
90 }
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
XML is a class representing xml object.
Definition: XML.hpp:72