ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
(Generate patch)

Comparing projects/cms/source/host/c++/XMLFormatter.cpp (file contents):
Revision 1.2 by ab11, Wed Jan 24 19:33:37 2001 UTC vs.
Revision 1.9 by tdb, Tue May 21 16:47:11 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
4 + * Copyright (C) 2000-2002 i-scream
5 + *
6 + * This program is free software; you can redistribute it and/or
7 + * modify it under the terms of the GNU General Public License
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21   #include "XMLFormatter.h"
22  
23   XMLFormatter::XMLFormatter( string newHostInfo ){
4        // std::cout << "DEBUG: " << newHostInfo << "\n";
5        xmlData += "<";
6        xmlData += newHostInfo;
7        xmlData += ">";
24          
25 <        hostInfo = newHostInfo;
10 <        // std::cout << "DEBUG: xmldata: " << xmlData << "\n";
25 >        if ( newHostInfo != "" ){
26          
27 +        xmlData += "<";
28 +        xmlData += newHostInfo;
29 +        xmlData += ">";
30 +        hostInfo = newHostInfo;
31 +        
32 +        } // if
33          stackPointer = 0;
34 < }
34 >        
35 > } // XMLFormatter
36  
37 < XMLFormatter::XMLFormatter( ){
38 <        // std::cout << "DEBUG: " << "No Root info" << "\n";
37 > XMLFormatter::XMLFormatter(){
38 >        
39          hostInfo = ""; // null
40 <        xmlData = hostInfo;
40 >        xmlData = "";
41          stackPointer = 0;
42 < }
42 >        
43 > } // XMLFormatter
44  
45   XMLFormatter::XMLFormatter( string newHostInfo, string attributes){
46 <        // std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n";
46 >        
47          xmlData += "<";
48          xmlData += newHostInfo;
49 +        xmlData += " ";
50 +        xmlData += attributes;
51          xmlData += ">";
52          
53          hostInfo = newHostInfo;
54          
55          stackPointer = 0;
56 < }
56 > } // XMLFormatter
57  
58   void XMLFormatter::closeNest(){
34        // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n";
35        stackPointer--;
36        xmlData += "</";
37        xmlData += stack[stackPointer];
38        xmlData += ">";
59          
60 +        if ( stackPointer >= 0 ){
61 +        
62 +        stackPointer--;
63 +        xmlData += "</";
64 +        xmlData += stack[stackPointer];
65 +        xmlData += ">";
66 +        } // if
67 +        
68          return;
69 < }
69 > } // closeNest
70  
71   void XMLFormatter::addNest(string nest){
44        // std::cout << "DEBUG: Adding Nest: " << nest << "\n";
45        xmlData += "<";
46        xmlData += nest;
47        xmlData += ">";
48        
49        // now add the nest to the stack
50        stack[stackPointer] = nest;
51        stackPointer++;
52        return;
53 }
72  
73 +        // check it is not empty
74 +        if ( nest != "" ){
75 +        xmlData += "<";
76 +        xmlData += nest;
77 +        xmlData += ">";
78 +        
79 +        // now add the nest to the stack
80 +        stack[stackPointer] = nest;
81 +        stackPointer++;
82 +    } // if
83 +    
84 +    return;    
85 + } // addNest
86 +
87   void XMLFormatter::addElement(string element, string attributes, string value){
88 <        // std::cout << "DEBUG: Add Element: " << element << ":" << attributes << ":" << value << "\n";
88 >        
89          xmlData += "<";
90          xmlData += element;
91          xmlData += " ";
92          xmlData += attributes;
93          xmlData += ">";
94 <        xmlData += value;
95 <        xmlData += "</";
96 <        xmlData += element;
97 <        xmlData += ">";
66 <        return;
67 < }
94 >        xmlData += value;
95 >        xmlData += "</";
96 >        xmlData += element;
97 >        xmlData += ">";
98  
99 +    return;
100 + } // addElement
101 +
102   void XMLFormatter::addElement(string element, string value){
103 <        // std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n";
104 <        xmlData += "<";
105 <        xmlData += element;
106 <        xmlData += ">";
107 <        xmlData += value;
108 <        xmlData += "</";
109 <        xmlData += element;
110 <        xmlData += ">";
111 <        return;
112 < }
103 >                
104 >        if (( element != "" ) && ( value != "" )){
105 >        xmlData += "<";
106 >        xmlData += element;
107 >        xmlData += ">";
108 >        xmlData += value;
109 >        xmlData += "</";
110 >        xmlData += element;
111 >        xmlData += ">";
112 >    } // if
113 >    return;
114 >    
115 > } // addElement
116  
117  
118   string XMLFormatter::returnXML(){
# Line 85 | Line 121 | string XMLFormatter::returnXML(){
121          for ( int count= stackPointer; count > 0; count-- ){
122                  // close nest
123                  closeNest();    
124 <        }
124 >        } // if
125          
126 <        if ( hostInfo.length() != 0 ){
127 <                xmlData += "</";
126 >        if ( hostInfo.length() > 0 ){
127 >            xmlData += "</";
128                  xmlData += hostInfo;
129                  xmlData += ">";
130 <        }
130 >        } // if
131          
132 <        // std::cout << "DEBUG: returning XML: " << xmlData;
132 >        stackPointer = 0;
133 >        
134          return xmlData;
135 < }
135 >        
136 > } // returnXML

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines