2 |
|
|
3 |
|
XMLFormatter::XMLFormatter( string newHostInfo ){ |
4 |
|
// std::cout << "DEBUG: " << newHostInfo << "\n"; |
5 |
< |
xmlData += "<"; |
6 |
< |
xmlData += newHostInfo; |
7 |
< |
xmlData += ">"; |
5 |
> |
if ( newHostInfo != "" ){ |
6 |
|
|
7 |
< |
hostInfo = newHostInfo; |
8 |
< |
// std::cout << "DEBUG: xmldata: " << xmlData << "\n"; |
9 |
< |
|
7 |
> |
xmlData += "<"; |
8 |
> |
xmlData += newHostInfo; |
9 |
> |
xmlData += ">"; |
10 |
> |
|
11 |
> |
hostInfo = newHostInfo; |
12 |
> |
// std::cout << "DEBUG: xmldata: " << xmlData << "\n"; |
13 |
> |
} |
14 |
|
stackPointer = 0; |
15 |
|
} |
16 |
|
|
17 |
< |
XMLFormatter::XMLFormatter( ){ |
17 |
> |
XMLFormatter::XMLFormatter(){ |
18 |
|
// std::cout << "DEBUG: " << "No Root info" << "\n"; |
19 |
|
hostInfo = ""; // null |
20 |
< |
xmlData = hostInfo; |
20 |
> |
xmlData = ""; |
21 |
|
stackPointer = 0; |
22 |
|
} |
23 |
|
|
25 |
|
// std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n"; |
26 |
|
xmlData += "<"; |
27 |
|
xmlData += newHostInfo; |
28 |
+ |
xmlData += " "; |
29 |
+ |
xmlData += attributes; |
30 |
|
xmlData += ">"; |
31 |
|
|
32 |
|
hostInfo = newHostInfo; |
36 |
|
|
37 |
|
void XMLFormatter::closeNest(){ |
38 |
|
// std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; |
39 |
< |
stackPointer--; |
40 |
< |
xmlData += "</"; |
41 |
< |
xmlData += stack[stackPointer]; |
42 |
< |
xmlData += ">"; |
39 |
> |
if ( stackPointer >= 0 ){ |
40 |
> |
|
41 |
> |
stackPointer--; |
42 |
> |
xmlData += "</"; |
43 |
> |
xmlData += stack[stackPointer]; |
44 |
> |
xmlData += ">"; |
45 |
> |
} |
46 |
|
|
47 |
|
return; |
48 |
|
} |
49 |
|
|
50 |
|
void XMLFormatter::addNest(string nest){ |
51 |
|
// std::cout << "DEBUG: Adding Nest: " << nest << "\n"; |
45 |
– |
xmlData += "<"; |
46 |
– |
xmlData += nest; |
47 |
– |
xmlData += ">"; |
52 |
|
|
53 |
< |
// now add the nest to the stack |
54 |
< |
stack[stackPointer] = nest; |
55 |
< |
stackPointer++; |
56 |
< |
return; |
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 |
|
} |
66 |
|
|
67 |
|
void XMLFormatter::addElement(string element, string attributes, string value){ |
71 |
|
xmlData += " "; |
72 |
|
xmlData += attributes; |
73 |
|
xmlData += ">"; |
74 |
< |
xmlData += value; |
75 |
< |
xmlData += "</"; |
76 |
< |
xmlData += element; |
77 |
< |
xmlData += ">"; |
78 |
< |
return; |
74 |
> |
xmlData += value; |
75 |
> |
xmlData += "</"; |
76 |
> |
xmlData += element; |
77 |
> |
xmlData += ">"; |
78 |
> |
|
79 |
> |
return; |
80 |
|
} |
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; |
84 |
> |
|
85 |
> |
if (( element != "" ) && ( value != "" )){ |
86 |
> |
xmlData += "<"; |
87 |
> |
xmlData += element; |
88 |
> |
xmlData += ">"; |
89 |
> |
xmlData += value; |
90 |
> |
xmlData += "</"; |
91 |
> |
xmlData += element; |
92 |
> |
xmlData += ">"; |
93 |
> |
} // if |
94 |
> |
return; |
95 |
|
} |
96 |
|
|
97 |
|
|
103 |
|
closeNest(); |
104 |
|
} |
105 |
|
|
106 |
< |
if ( hostInfo.length() != 0 ){ |
107 |
< |
xmlData += "</"; |
106 |
> |
if ( hostInfo.length() > 0 ){ |
107 |
> |
xmlData += "</"; |
108 |
|
xmlData += hostInfo; |
109 |
|
xmlData += ">"; |
110 |
|
} |
111 |
+ |
|
112 |
+ |
stackPointer = 0; |
113 |
|
|
114 |
|
// std::cout << "DEBUG: returning XML: " << xmlData; |
115 |
|
return xmlData; |