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.1 by ab11, Thu Nov 30 21:58:30 2000 UTC vs.
Revision 1.6 by ab11, Fri Mar 23 16:38:34 2001 UTC

# Line 1 | Line 1
1 < #include <XMLFormatter.h>
1 > #include "XMLFormatter.h"
2  
3 < void XMLFormatter::XMLFormatter( char* newHostInfo ){
4 <        hostInfo = "<"+newHostInfo+">";
3 > XMLFormatter::XMLFormatter( string newHostInfo ){
4 >        // std::cout << "DEBUG: " << newHostInfo << "\n";
5 >        if ( newHostInfo != "" ){
6 >        
7 >        xmlData += "<";
8 >        xmlData += newHostInfo;
9 >        xmlData += ">";
10 >        
11 >        hostInfo = newHostInfo;
12 >        // std::cout << "DEBUG: xmldata: " << xmlData << "\n";
13 >        }
14 >        stackPointer = 0;
15   }
16  
17 + XMLFormatter::XMLFormatter(){
18 +        // std::cout << "DEBUG: " << "No Root info" << "\n";
19 +        hostInfo = ""; // null
20 +        xmlData = "";
21 +        stackPointer = 0;
22 + }
23 +
24 + XMLFormatter::XMLFormatter( string newHostInfo, string attributes){
25 +        // std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n";
26 +        xmlData += "<";
27 +        xmlData += newHostInfo;
28 +        xmlData += " ";
29 +        xmlData += attributes;
30 +        xmlData += ">";
31 +        
32 +        hostInfo = newHostInfo;
33 +        
34 +        stackPointer = 0;
35 + }
36 +
37   void XMLFormatter::closeNest(){
38 +        // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n";
39 +        if ( stackPointer >= 0 ){
40 +        
41 +        stackPointer--;
42 +        xmlData += "</";
43 +        xmlData += stack[stackPointer];
44 +        xmlData += ">";
45 +        }
46 +        
47          return;
48   }
49  
50 < void XMLFormatter::addNest(char* nest){
51 <        return;
50 > void XMLFormatter::addNest(string nest){
51 >        // std::cout << "DEBUG: Adding Nest: " << nest << "\n";
52 >        
53 >        // 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   }
66  
67 < void XMLFormatter::addElement(char* element){
68 <        return;
67 > 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 >        xmlData += value;
75 >        xmlData += "</";
76 >        xmlData += element;
77 >        xmlData += ">";
78 >
79 >    return;
80   }
81  
82 < char* XMLFormatter::returnXML(){
83 <        return "hellO";
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 >        xmlData += value;
90 >        xmlData += "</";
91 >        xmlData += element;
92 >        xmlData += ">";
93 >    } // if
94 >    return;
95 > }
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 >        if ( hostInfo.length() > 0 ){
107 >            xmlData += "</";
108 >                xmlData += hostInfo;
109 >                xmlData += ">";
110 >        }
111 >        
112 >        stackPointer = 0;
113 >        
114 >        // std::cout << "DEBUG: returning XML: " << xmlData;
115 >        return xmlData;
116   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines