1 |
|
#include "XMLFormatter.h" |
2 |
|
|
3 |
|
XMLFormatter::XMLFormatter( string newHostInfo ){ |
4 |
– |
// std::cout << "DEBUG: " << newHostInfo << "\n"; |
5 |
– |
xmlData += "<"; |
6 |
– |
xmlData += newHostInfo; |
7 |
– |
xmlData += ">"; |
4 |
|
|
5 |
< |
hostInfo = newHostInfo; |
10 |
< |
// std::cout << "DEBUG: xmldata: " << xmlData << "\n"; |
5 |
> |
if ( newHostInfo != "" ){ |
6 |
|
|
7 |
+ |
xmlData += "<"; |
8 |
+ |
xmlData += newHostInfo; |
9 |
+ |
xmlData += ">"; |
10 |
+ |
hostInfo = newHostInfo; |
11 |
+ |
|
12 |
+ |
} // if |
13 |
|
stackPointer = 0; |
14 |
< |
} |
14 |
> |
|
15 |
> |
} // XMLFormatter |
16 |
|
|
17 |
< |
XMLFormatter::XMLFormatter( ){ |
18 |
< |
// std::cout << "DEBUG: " << "No Root info" << "\n"; |
17 |
> |
XMLFormatter::XMLFormatter(){ |
18 |
> |
|
19 |
|
hostInfo = ""; // null |
20 |
< |
xmlData = hostInfo; |
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(){ |
36 |
– |
// std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; |
37 |
– |
stackPointer--; |
38 |
– |
xmlData += "</"; |
39 |
– |
xmlData += stack[stackPointer]; |
40 |
– |
xmlData += ">"; |
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(string nest){ |
46 |
– |
// std::cout << "DEBUG: Adding Nest: " << nest << "\n"; |
47 |
– |
xmlData += "<"; |
48 |
– |
xmlData += nest; |
49 |
– |
xmlData += ">"; |
50 |
– |
|
51 |
– |
// now add the nest to the stack |
52 |
– |
stack[stackPointer] = nest; |
53 |
– |
stackPointer++; |
54 |
– |
return; |
55 |
– |
} |
52 |
|
|
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 |
|
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 += " "; |
72 |
|
xmlData += attributes; |
73 |
|
xmlData += ">"; |
74 |
< |
xmlData += value; |
75 |
< |
xmlData += "</"; |
76 |
< |
xmlData += element; |
77 |
< |
xmlData += ">"; |
68 |
< |
return; |
69 |
< |
} |
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 |
< |
// std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n"; |
84 |
< |
xmlData += "<"; |
85 |
< |
xmlData += element; |
86 |
< |
xmlData += ">"; |
87 |
< |
xmlData += value; |
88 |
< |
xmlData += "</"; |
89 |
< |
xmlData += element; |
90 |
< |
xmlData += ">"; |
91 |
< |
return; |
92 |
< |
} |
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(){ |
101 |
|
for ( int count= stackPointer; count > 0; count-- ){ |
102 |
|
// close nest |
103 |
|
closeNest(); |
104 |
< |
} |
104 |
> |
} // if |
105 |
|
|
106 |
< |
if ( hostInfo.length() != 0 ){ |
107 |
< |
xmlData += "</"; |
106 |
> |
if ( hostInfo.length() > 0 ){ |
107 |
> |
xmlData += "</"; |
108 |
|
xmlData += hostInfo; |
109 |
|
xmlData += ">"; |
110 |
< |
} |
110 |
> |
} // if |
111 |
|
|
112 |
< |
// std::cout << "DEBUG: returning XML: " << xmlData; |
112 |
> |
stackPointer = 0; |
113 |
> |
|
114 |
|
return xmlData; |
115 |
< |
} |
115 |
> |
|
116 |
> |
} // returnXML |