-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXMLWriter.cpp
56 lines (40 loc) · 1.16 KB
/
XMLWriter.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
#include "XMLWriter.h"
XMLWriter::XMLWriter (string filePath)
{
m_filePath = filePath;
openFile ();
}
bool XMLWriter::openFile ()
{
m_file.open(m_filePath.c_str());
if (m_file.good())
m_file << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
return m_file.good();
}
void XMLWriter::WriteGroup (vector<string> tags, vector<string> elements)
{
//Collect the group tag to use at closing
string groupTag = tags.back();
m_file << "<" + groupTag + ">\n";
tags.pop_back ();
vector<string>::iterator i;
vector<string>::iterator v;
for (i = tags.begin(), v = elements.begin();
i != tags.end() &&
v != elements.end();
i++,
v++)
{
WriteLine ((*i), (*v));
}
m_file << "</" + groupTag + ">\n";
return;
}
void XMLWriter::WriteLine (string tag, string element)
{
m_file << "\t"
<< "<" + tag + ">"
<< element
<< "</" + tag + ">\n";
return;
}