ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.4
Committed: Mon Feb 26 14:54:13 2001 UTC (23 years, 9 months ago) by ab11
Branch: MAIN
Changes since 1.3: +2 -0 lines
Log Message:
Final Version

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     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 = hostInfo;
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 ab11 1.4 xmlData += " ";
27     xmlData += attributes;
28 ab11 1.2 xmlData += ">";
29    
30     hostInfo = newHostInfo;
31    
32     stackPointer = 0;
33 ab11 1.1 }
34    
35     void XMLFormatter::closeNest(){
36 ab11 1.2 // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n";
37     stackPointer--;
38     xmlData += "</";
39     xmlData += stack[stackPointer];
40     xmlData += ">";
41    
42 ab11 1.1 return;
43     }
44    
45 ab11 1.2 void XMLFormatter::addNest(string nest){
46     // std::cout << "DEBUG: Adding Nest: " << nest << "\n";
47     xmlData += "<";
48     xmlData += nest;
49     xmlData += ">";
50    
51     // now add the nest to the stack
52     stack[stackPointer] = nest;
53     stackPointer++;
54 ab11 1.1 return;
55     }
56    
57 ab11 1.2 void XMLFormatter::addElement(string element, string attributes, string value){
58     // std::cout << "DEBUG: Add Element: " << element << ":" << attributes << ":" << value << "\n";
59     xmlData += "<";
60     xmlData += element;
61     xmlData += " ";
62     xmlData += attributes;
63     xmlData += ">";
64     xmlData += value;
65     xmlData += "</";
66     xmlData += element;
67     xmlData += ">";
68 ab11 1.1 return;
69     }
70    
71 ab11 1.2 void XMLFormatter::addElement(string element, string value){
72     // std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n";
73     xmlData += "<";
74     xmlData += element;
75     xmlData += ">";
76     xmlData += value;
77     xmlData += "</";
78     xmlData += element;
79     xmlData += ">";
80     return;
81     }
82    
83    
84     string XMLFormatter::returnXML(){
85     // close as many nests as we have open, could (but shouldn't) cause
86     // some arraylist out of bounds errors.
87     for ( int count= stackPointer; count > 0; count-- ){
88     // close nest
89     closeNest();
90     }
91    
92     if ( hostInfo.length() != 0 ){
93     xmlData += "</";
94     xmlData += hostInfo;
95     xmlData += ">";
96     }
97    
98     // std::cout << "DEBUG: returning XML: " << xmlData;
99     return xmlData;
100 ab11 1.1 }