--- projects/cms/source/host/c++/XMLFormatter.cpp 2000/11/30 21:58:30 1.1 +++ projects/cms/source/host/c++/XMLFormatter.cpp 2001/03/23 16:38:34 1.6 @@ -1,21 +1,116 @@ -#include +#include "XMLFormatter.h" -void XMLFormatter::XMLFormatter( char* newHostInfo ){ - hostInfo = "<"+newHostInfo+">"; +XMLFormatter::XMLFormatter( string newHostInfo ){ + // std::cout << "DEBUG: " << newHostInfo << "\n"; + if ( newHostInfo != "" ){ + + xmlData += "<"; + xmlData += newHostInfo; + xmlData += ">"; + + hostInfo = newHostInfo; + // std::cout << "DEBUG: xmldata: " << xmlData << "\n"; + } + stackPointer = 0; } +XMLFormatter::XMLFormatter(){ + // std::cout << "DEBUG: " << "No Root info" << "\n"; + hostInfo = ""; // null + xmlData = ""; + stackPointer = 0; +} + +XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ + // std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n"; + xmlData += "<"; + xmlData += newHostInfo; + xmlData += " "; + xmlData += attributes; + xmlData += ">"; + + hostInfo = newHostInfo; + + stackPointer = 0; +} + void XMLFormatter::closeNest(){ + // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; + if ( stackPointer >= 0 ){ + + stackPointer--; + xmlData += ""; + } + return; } -void XMLFormatter::addNest(char* nest){ - return; +void XMLFormatter::addNest(string nest){ + // std::cout << "DEBUG: Adding Nest: " << nest << "\n"; + + // check it is not empty + if ( nest != "" ){ + xmlData += "<"; + xmlData += nest; + xmlData += ">"; + + // now add the nest to the stack + stack[stackPointer] = nest; + stackPointer++; + } // if + + return; } -void XMLFormatter::addElement(char* element){ - return; +void XMLFormatter::addElement(string element, string attributes, string value){ + // std::cout << "DEBUG: Add Element: " << element << ":" << attributes << ":" << value << "\n"; + xmlData += "<"; + xmlData += element; + xmlData += " "; + xmlData += attributes; + xmlData += ">"; + xmlData += value; + xmlData += ""; + + return; } -char* XMLFormatter::returnXML(){ - return "hellO"; +void XMLFormatter::addElement(string element, string value){ + // std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n"; + + if (( element != "" ) && ( value != "" )){ + xmlData += "<"; + xmlData += element; + xmlData += ">"; + xmlData += value; + xmlData += ""; + } // if + return; +} + + +string XMLFormatter::returnXML(){ + // close as many nests as we have open, could (but shouldn't) cause + // some arraylist out of bounds errors. + for ( int count= stackPointer; count > 0; count-- ){ + // close nest + closeNest(); + } + + if ( hostInfo.length() > 0 ){ + xmlData += ""; + } + + stackPointer = 0; + + // std::cout << "DEBUG: returning XML: " << xmlData; + return xmlData; } \ No newline at end of file