ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.7
Committed: Tue Mar 27 00:03:56 2001 UTC (23 years, 8 months ago) by ab11
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.6: +24 -24 lines
Log Message:
tidied up and fixed a few range check errors

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 ab11 1.7
5 ab11 1.6 if ( newHostInfo != "" ){
6 ab11 1.2
7 ab11 1.6 xmlData += "<";
8     xmlData += newHostInfo;
9     xmlData += ">";
10 ab11 1.7 hostInfo = newHostInfo;
11 ab11 1.6
12 ab11 1.7 } // if
13 ab11 1.2 stackPointer = 0;
14 ab11 1.7
15     } // XMLFormatter
16 ab11 1.2
17 ab11 1.5 XMLFormatter::XMLFormatter(){
18 ab11 1.7
19 ab11 1.2 hostInfo = ""; // null
20 ab11 1.5 xmlData = "";
21 ab11 1.2 stackPointer = 0;
22 ab11 1.7
23     } // XMLFormatter
24 ab11 1.2
25     XMLFormatter::XMLFormatter( string newHostInfo, string attributes){
26 ab11 1.7
27 ab11 1.2 xmlData += "<";
28     xmlData += newHostInfo;
29 ab11 1.4 xmlData += " ";
30     xmlData += attributes;
31 ab11 1.2 xmlData += ">";
32    
33     hostInfo = newHostInfo;
34    
35     stackPointer = 0;
36 ab11 1.7 } // XMLFormatter
37 ab11 1.1
38     void XMLFormatter::closeNest(){
39 ab11 1.7
40 ab11 1.5 if ( stackPointer >= 0 ){
41    
42     stackPointer--;
43     xmlData += "</";
44     xmlData += stack[stackPointer];
45     xmlData += ">";
46 ab11 1.7 } // if
47 ab11 1.2
48 ab11 1.1 return;
49 ab11 1.7 } // closeNest
50 ab11 1.1
51 ab11 1.2 void XMLFormatter::addNest(string nest){
52 ab11 1.7
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.7 } // addNest
66 ab11 1.1
67 ab11 1.2 void XMLFormatter::addElement(string element, string attributes, string value){
68 ab11 1.7
69 ab11 1.2 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 ab11 1.7 } // addElement
81 ab11 1.6
82     void XMLFormatter::addElement(string element, string value){
83 ab11 1.7
84 ab11 1.6 if (( element != "" ) && ( value != "" )){
85     xmlData += "<";
86     xmlData += element;
87     xmlData += ">";
88 ab11 1.5 xmlData += value;
89     xmlData += "</";
90     xmlData += element;
91     xmlData += ">";
92     } // if
93     return;
94 ab11 1.7
95     } // addElement
96 ab11 1.2
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 ab11 1.7 } // if
105 ab11 1.2
106 ab11 1.5 if ( hostInfo.length() > 0 ){
107     xmlData += "</";
108 ab11 1.2 xmlData += hostInfo;
109     xmlData += ">";
110 ab11 1.7 } // if
111 ab11 1.5
112     stackPointer = 0;
113 ab11 1.2
114     return xmlData;
115 ab11 1.7
116     } // returnXML