-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_parse.cpp
More file actions
57 lines (49 loc) · 1.93 KB
/
Copy pathupload_parse.cpp
File metadata and controls
57 lines (49 loc) · 1.93 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "tinyxml2.h"
using namespace std;
string lastline(string filename){
ifstream fin;
fin.open(filename.c_str());
string lastLine;
if(fin.is_open()) {
fin.seekg(-1,ios_base::end); // go to one spot before the EOF
bool keepLooping = true;
while(keepLooping) {
char ch;
fin.get(ch); // Get current byte's data
if((int)fin.tellg() <= 1) { // If the data was at or before the 0th byte
fin.seekg(0); // The first line is the last line
keepLooping = false; // So stop there
}
else if(ch == '\n') { // If the data was a newline
keepLooping = false; // Stop at the current position.
}
else { // If the data was neither a newline nor at the 0 byte
fin.seekg(-2,ios_base::cur); // Move to the front of that data, then to the front of the data before it
}
}
getline(fin,lastLine); // Read the current line
//cout << "Result: " << lastLine << '\n'; // Display it
fin.close();
}
return lastLine;
}
int main(){
//std::ifstream fupload("upload.xml");
string line = lastline("upload.xml");
//if last line is not </data></file_upload></data_server_request>, tinyxml parser cannot parse
//so add this temporaly for the purpose of parsing.
if (line != "</data></file_upload></data_server_request>"){
std::ofstream upload;
upload.open("upload.xml", std::ios_base::app);
upload << "</data>";
upload << "</file_upload>";
upload << "</data_server_request>";
upload.close();
}
tinyxml2::XMLDocument upload_doc;
upload_doc.LoadFile("upload.xml");
}