ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.6
Committed: Fri Mar 23 16:38:34 2001 UTC (23 years, 6 months ago) by ab11
Branch: MAIN
Changes since 1.5: +35 -26 lines
Log Message:
added in the closing tags on an attribute again

File Contents

# User Rev Content
1 ab11 1.2 #include "XMLFormatter.h"
2 ab11 1.1
3 ab11 1.2 XMLFormatter::XMLFormatter( string newHostInfo ){
4     // std::cout << "DEBUG: " << newHostInfo << "\n";
5 ab11 1.6 if ( newHostInfo != "" ){
6 ab11 1.2
7 ab11 1.6 xmlData += "<";
8     xmlData += newHostInfo;
9     xmlData += ">";
10    
11     hostInfo = newHostInfo;
12     // std::cout << "DEBUG: xmldata: " << xmlData << "\n";
13     }
14 ab11 1.2 stackPointer = 0;
15     }
16    
17 ab11 1.5 XMLFormatter::XMLFormatter(){
18 ab11 1.2 // std::cout << "DEBUG: " << "No Root info" << "\n";
19     hostInfo = ""; // null
20 ab11 1.5 xmlData = "";
21 ab11 1.2 stackPointer = 0;
22     }
23    
24     XMLFormatter::XMLFormatter( string newHostInfo, string attributes){
25     // std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n";
26     xmlData += "<";
27     xmlData += newHostInfo;
28 ab11 1.4 xmlData += " ";
29     xmlData += attributes;
30 ab11 1.2 xmlData += ">";
31    
32     hostInfo = newHostInfo;
33    
34     stackPointer = 0;
35 ab11 1.1 }
36    
37     void XMLFormatter::closeNest(){
38 ab11 1.2 // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n";
39 ab11 1.5 if ( stackPointer >= 0 ){
40    
41     stackPointer--;
42     xmlData += "</";
43     xmlData += stack[stackPointer];
44     xmlData += ">";
45     }
46 ab11 1.2
47 ab11 1.1 return;
48     }
49    
50 ab11 1.2 void XMLFormatter::addNest(string nest){
51     // std::cout << "DEBUG: Adding Nest: " << nest << "\n";
52    
53 ab11 1.6 // 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 ab11 1.1 }
66    
67 ab11 1.2 void XMLFormatter::addElement(string element, string attributes, string value){
68     // std::cout << "DEBUG: Add Element: " << element << ":" << attributes << ":" << value << "\n";
69     xmlData += "<";
70     xmlData += element;
71     xmlData += " ";
72     xmlData += attributes;
73     xmlData += ">";
74 ab11 1.6 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    
85     if (( element != "" ) && ( value != "" )){
86     xmlData += "<";
87     xmlData += element;
88     xmlData += ">";
89 ab11 1.5 xmlData += value;
90     xmlData += "</";
91     xmlData += element;
92     xmlData += ">";
93     } // if
94     return;
95 ab11 1.2 }
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     }
105    
106 ab11 1.5 if ( hostInfo.length() > 0 ){
107     xmlData += "</";
108 ab11 1.2 xmlData += hostInfo;
109     xmlData += ">";
110     }
111 ab11 1.5
112     stackPointer = 0;
113 ab11 1.2
114     // std::cout << "DEBUG: returning XML: " << xmlData;
115     return xmlData;
116 ab11 1.1 }