1 |
< |
#include <XMLFormatter.h> |
1 |
> |
#include "XMLFormatter.h" |
2 |
|
|
3 |
< |
void XMLFormatter::XMLFormatter( char* newHostInfo ){ |
4 |
< |
hostInfo = "<"+newHostInfo+">"; |
5 |
< |
} |
3 |
> |
XMLFormatter::XMLFormatter( string newHostInfo ){ |
4 |
> |
|
5 |
> |
if ( newHostInfo != "" ){ |
6 |
> |
|
7 |
> |
xmlData += "<"; |
8 |
> |
xmlData += newHostInfo; |
9 |
> |
xmlData += ">"; |
10 |
> |
hostInfo = newHostInfo; |
11 |
> |
|
12 |
> |
} // if |
13 |
> |
stackPointer = 0; |
14 |
> |
|
15 |
> |
} // XMLFormatter |
16 |
|
|
17 |
+ |
XMLFormatter::XMLFormatter(){ |
18 |
+ |
|
19 |
+ |
hostInfo = ""; // null |
20 |
+ |
xmlData = ""; |
21 |
+ |
stackPointer = 0; |
22 |
+ |
|
23 |
+ |
} // XMLFormatter |
24 |
+ |
|
25 |
+ |
XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ |
26 |
+ |
|
27 |
+ |
xmlData += "<"; |
28 |
+ |
xmlData += newHostInfo; |
29 |
+ |
xmlData += " "; |
30 |
+ |
xmlData += attributes; |
31 |
+ |
xmlData += ">"; |
32 |
+ |
|
33 |
+ |
hostInfo = newHostInfo; |
34 |
+ |
|
35 |
+ |
stackPointer = 0; |
36 |
+ |
} // XMLFormatter |
37 |
+ |
|
38 |
|
void XMLFormatter::closeNest(){ |
39 |
+ |
|
40 |
+ |
if ( stackPointer >= 0 ){ |
41 |
+ |
|
42 |
+ |
stackPointer--; |
43 |
+ |
xmlData += "</"; |
44 |
+ |
xmlData += stack[stackPointer]; |
45 |
+ |
xmlData += ">"; |
46 |
+ |
} // if |
47 |
+ |
|
48 |
|
return; |
49 |
< |
} |
49 |
> |
} // closeNest |
50 |
|
|
51 |
< |
void XMLFormatter::addNest(char* nest){ |
12 |
< |
return; |
13 |
< |
} |
51 |
> |
void XMLFormatter::addNest(string nest){ |
52 |
|
|
53 |
< |
void XMLFormatter::addElement(char* element){ |
54 |
< |
return; |
55 |
< |
} |
53 |
> |
// check it is not empty |
54 |
> |
if ( nest != "" ){ |
55 |
> |
xmlData += "<"; |
56 |
> |
xmlData += nest; |
57 |
> |
xmlData += ">"; |
58 |
> |
|
59 |
> |
// now add the nest to the stack |
60 |
> |
stack[stackPointer] = nest; |
61 |
> |
stackPointer++; |
62 |
> |
} // if |
63 |
> |
|
64 |
> |
return; |
65 |
> |
} // addNest |
66 |
|
|
67 |
< |
char* XMLFormatter::returnXML(){ |
68 |
< |
return "hellO"; |
69 |
< |
} |
67 |
> |
void XMLFormatter::addElement(string element, string attributes, string value){ |
68 |
> |
|
69 |
> |
xmlData += "<"; |
70 |
> |
xmlData += element; |
71 |
> |
xmlData += " "; |
72 |
> |
xmlData += attributes; |
73 |
> |
xmlData += ">"; |
74 |
> |
xmlData += value; |
75 |
> |
xmlData += "</"; |
76 |
> |
xmlData += element; |
77 |
> |
xmlData += ">"; |
78 |
> |
|
79 |
> |
return; |
80 |
> |
} // addElement |
81 |
> |
|
82 |
> |
void XMLFormatter::addElement(string element, string value){ |
83 |
> |
|
84 |
> |
if (( element != "" ) && ( value != "" )){ |
85 |
> |
xmlData += "<"; |
86 |
> |
xmlData += element; |
87 |
> |
xmlData += ">"; |
88 |
> |
xmlData += value; |
89 |
> |
xmlData += "</"; |
90 |
> |
xmlData += element; |
91 |
> |
xmlData += ">"; |
92 |
> |
} // if |
93 |
> |
return; |
94 |
> |
|
95 |
> |
} // addElement |
96 |
> |
|
97 |
> |
|
98 |
> |
string XMLFormatter::returnXML(){ |
99 |
> |
// close as many nests as we have open, could (but shouldn't) cause |
100 |
> |
// some arraylist out of bounds errors. |
101 |
> |
for ( int count= stackPointer; count > 0; count-- ){ |
102 |
> |
// close nest |
103 |
> |
closeNest(); |
104 |
> |
} // if |
105 |
> |
|
106 |
> |
if ( hostInfo.length() > 0 ){ |
107 |
> |
xmlData += "</"; |
108 |
> |
xmlData += hostInfo; |
109 |
> |
xmlData += ">"; |
110 |
> |
} // if |
111 |
> |
|
112 |
> |
stackPointer = 0; |
113 |
> |
|
114 |
> |
return xmlData; |
115 |
> |
|
116 |
> |
} // returnXML |