ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.2
Committed: Wed Jan 24 19:33:37 2001 UTC (23 years, 10 months ago) by ab11
Branch: MAIN
Changes since 1.1: +84 -7 lines
Log Message:
XMLFormatter (final?)

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