ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.5
Committed: Fri Mar 23 14:07:11 2001 UTC (23 years, 7 months ago) by ab11
Branch: MAIN
Changes since 1.4: +20 -13 lines
Log Message:
put in some error checking to stop possible segmentation faults

File Contents

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