--- projects/cms/source/host/c++/XMLFormatter.cpp 2000/11/30 21:58:30 1.1 +++ projects/cms/source/host/c++/XMLFormatter.cpp 2001/03/27 00:03:56 1.7 @@ -1,21 +1,116 @@ -#include +#include "XMLFormatter.h" -void XMLFormatter::XMLFormatter( char* newHostInfo ){ - hostInfo = "<"+newHostInfo+">"; -} +XMLFormatter::XMLFormatter( string newHostInfo ){ + + if ( newHostInfo != "" ){ + + xmlData += "<"; + xmlData += newHostInfo; + xmlData += ">"; + hostInfo = newHostInfo; + + } // if + stackPointer = 0; + +} // XMLFormatter +XMLFormatter::XMLFormatter(){ + + hostInfo = ""; // null + xmlData = ""; + stackPointer = 0; + +} // XMLFormatter + +XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ + + xmlData += "<"; + xmlData += newHostInfo; + xmlData += " "; + xmlData += attributes; + xmlData += ">"; + + hostInfo = newHostInfo; + + stackPointer = 0; +} // XMLFormatter + void XMLFormatter::closeNest(){ + + if ( stackPointer >= 0 ){ + + stackPointer--; + xmlData += ""; + } // if + return; -} +} // closeNest -void XMLFormatter::addNest(char* nest){ - return; -} +void XMLFormatter::addNest(string nest){ -void XMLFormatter::addElement(char* element){ - return; -} + // check it is not empty + if ( nest != "" ){ + xmlData += "<"; + xmlData += nest; + xmlData += ">"; + + // now add the nest to the stack + stack[stackPointer] = nest; + stackPointer++; + } // if + + return; +} // addNest -char* XMLFormatter::returnXML(){ - return "hellO"; -} \ No newline at end of file +void XMLFormatter::addElement(string element, string attributes, string value){ + + xmlData += "<"; + xmlData += element; + xmlData += " "; + xmlData += attributes; + xmlData += ">"; + xmlData += value; + xmlData += ""; + + return; +} // addElement + +void XMLFormatter::addElement(string element, string value){ + + if (( element != "" ) && ( value != "" )){ + xmlData += "<"; + xmlData += element; + xmlData += ">"; + xmlData += value; + xmlData += ""; + } // if + return; + +} // addElement + + +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 + + if ( hostInfo.length() > 0 ){ + xmlData += ""; + } // if + + stackPointer = 0; + + return xmlData; + +} // returnXML \ No newline at end of file