-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (51 loc) · 1.62 KB
/
main.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
69
70
71
72
73
74
75
#include "sources.cpp"
#include <fstream>
#include <string>
using namespace std;
using namespace rapidxml;
char* readFileContent(const std::string& fileName) {
std::ifstream fileStream(fileName, std::ios::in | std::ios::binary);
if (!fileStream.is_open()) {
std::cerr << "Failed to open file: " << fileName << std::endl;
return nullptr;
}
fileStream.seekg(0, std::ios::end);
std::streamoff fileSize = fileStream.tellg();
fileStream.seekg(0, std::ios::beg);
char* buffer = new char[fileSize + 1];
fileStream.read(buffer, fileSize);
buffer[fileSize] = '\0'; // Null terminate the buffer
fileStream.close();
return buffer;
}
bool createHTMLFile(const std::string& file_name, const std::string& source) {
std::ofstream file(file_name, std::ios::out);
if (!file) {
std::cerr << "Error: Unable to create file " << file_name << std::endl;
return false;
}
file << source;
file.close();
std::cout << "File " << file_name << " created successfully." << std::endl;
return true;
}
int getChildElementCount(xml_node<>& node) {
xml_node<>* child = node.first_node();
int count = 0;
while (child != nullptr) {
if (child->type() == node_element) {
count++;
}
child = child->next_sibling();
}
return count;
}
int main(int argc , const char* argv[]){
xml_document<> doc;
char* file_data=readFileContent("file.xml");
doc.parse<0>(file_data);
xml_node<> *root=doc.first_node("root");
SourceParser parser(root);
cout<<"Title:"<<parser.getTitle()<<endl;
return 0;
}