1 |
|
#include "XMLFormatter.h" |
2 |
|
|
3 |
|
XMLFormatter::XMLFormatter( string newHostInfo ){ |
4 |
< |
// std::cout << "DEBUG: " << newHostInfo << "\n"; |
4 |
> |
|
5 |
|
if ( newHostInfo != "" ){ |
6 |
|
|
7 |
|
xmlData += "<"; |
8 |
|
xmlData += newHostInfo; |
9 |
|
xmlData += ">"; |
10 |
– |
|
10 |
|
hostInfo = newHostInfo; |
11 |
< |
// std::cout << "DEBUG: xmldata: " << xmlData << "\n"; |
12 |
< |
} |
11 |
> |
|
12 |
> |
} // if |
13 |
|
stackPointer = 0; |
14 |
< |
} |
14 |
> |
|
15 |
> |
} // XMLFormatter |
16 |
|
|
17 |
|
XMLFormatter::XMLFormatter(){ |
18 |
< |
// std::cout << "DEBUG: " << "No Root info" << "\n"; |
18 |
> |
|
19 |
|
hostInfo = ""; // null |
20 |
|
xmlData = ""; |
21 |
|
stackPointer = 0; |
22 |
< |
} |
22 |
> |
|
23 |
> |
} // XMLFormatter |
24 |
|
|
25 |
|
XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ |
26 |
< |
// std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n"; |
26 |
> |
|
27 |
|
xmlData += "<"; |
28 |
|
xmlData += newHostInfo; |
29 |
|
xmlData += " "; |
33 |
|
hostInfo = newHostInfo; |
34 |
|
|
35 |
|
stackPointer = 0; |
36 |
< |
} |
36 |
> |
} // XMLFormatter |
37 |
|
|
38 |
|
void XMLFormatter::closeNest(){ |
39 |
< |
// std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; |
39 |
> |
|
40 |
|
if ( stackPointer >= 0 ){ |
41 |
|
|
42 |
|
stackPointer--; |
43 |
|
xmlData += "</"; |
44 |
|
xmlData += stack[stackPointer]; |
45 |
|
xmlData += ">"; |
46 |
< |
} |
46 |
> |
} // if |
47 |
|
|
48 |
|
return; |
49 |
< |
} |
49 |
> |
} // closeNest |
50 |
|
|
51 |
|
void XMLFormatter::addNest(string nest){ |
52 |
< |
// std::cout << "DEBUG: Adding Nest: " << nest << "\n"; |
52 |
< |
|
52 |
> |
|
53 |
|
// check it is not empty |
54 |
|
if ( nest != "" ){ |
55 |
|
xmlData += "<"; |
62 |
|
} // if |
63 |
|
|
64 |
|
return; |
65 |
< |
} |
65 |
> |
} // addNest |
66 |
|
|
67 |
|
void XMLFormatter::addElement(string element, string attributes, string value){ |
68 |
< |
// std::cout << "DEBUG: Add Element: " << element << ":" << attributes << ":" << value << "\n"; |
68 |
> |
|
69 |
|
xmlData += "<"; |
70 |
|
xmlData += element; |
71 |
|
xmlData += " "; |
77 |
|
xmlData += ">"; |
78 |
|
|
79 |
|
return; |
80 |
< |
} |
80 |
> |
} // addElement |
81 |
|
|
82 |
|
void XMLFormatter::addElement(string element, string value){ |
83 |
< |
// std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n"; |
84 |
< |
|
83 |
> |
|
84 |
|
if (( element != "" ) && ( value != "" )){ |
85 |
|
xmlData += "<"; |
86 |
|
xmlData += element; |
91 |
|
xmlData += ">"; |
92 |
|
} // if |
93 |
|
return; |
94 |
< |
} |
94 |
> |
|
95 |
> |
} // addElement |
96 |
|
|
97 |
|
|
98 |
|
string XMLFormatter::returnXML(){ |
101 |
|
for ( int count= stackPointer; count > 0; count-- ){ |
102 |
|
// close nest |
103 |
|
closeNest(); |
104 |
< |
} |
104 |
> |
} // if |
105 |
|
|
106 |
|
if ( hostInfo.length() > 0 ){ |
107 |
|
xmlData += "</"; |
108 |
|
xmlData += hostInfo; |
109 |
|
xmlData += ">"; |
110 |
< |
} |
110 |
> |
} // if |
111 |
|
|
112 |
|
stackPointer = 0; |
113 |
|
|
114 |
– |
// std::cout << "DEBUG: returning XML: " << xmlData; |
114 |
|
return xmlData; |
115 |
< |
} |
115 |
> |
|
116 |
> |
} // returnXML |