--- projects/cms/source/host/c++/XMLFormatter.cpp 2001/02/26 14:54:13 1.4 +++ projects/cms/source/host/c++/XMLFormatter.cpp 2001/03/27 00:03:56 1.7 @@ -1,26 +1,29 @@ #include "XMLFormatter.h" XMLFormatter::XMLFormatter( string newHostInfo ){ - // std::cout << "DEBUG: " << newHostInfo << "\n"; - xmlData += "<"; - xmlData += newHostInfo; - xmlData += ">"; - hostInfo = newHostInfo; - // std::cout << "DEBUG: xmldata: " << xmlData << "\n"; + if ( newHostInfo != "" ){ + xmlData += "<"; + xmlData += newHostInfo; + xmlData += ">"; + hostInfo = newHostInfo; + + } // if stackPointer = 0; -} + +} // XMLFormatter -XMLFormatter::XMLFormatter( ){ - // std::cout << "DEBUG: " << "No Root info" << "\n"; +XMLFormatter::XMLFormatter(){ + hostInfo = ""; // null - xmlData = hostInfo; + xmlData = ""; stackPointer = 0; -} + +} // XMLFormatter XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ - // std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n"; + xmlData += "<"; xmlData += newHostInfo; xmlData += " "; @@ -30,55 +33,66 @@ XMLFormatter::XMLFormatter( string newHostInfo, string hostInfo = newHostInfo; stackPointer = 0; -} +} // XMLFormatter void XMLFormatter::closeNest(){ - // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; - stackPointer--; - xmlData += ""; + if ( stackPointer >= 0 ){ + + stackPointer--; + xmlData += ""; + } // if + return; -} +} // closeNest void XMLFormatter::addNest(string nest){ - // std::cout << "DEBUG: Adding Nest: " << nest << "\n"; - xmlData += "<"; - xmlData += nest; - xmlData += ">"; - - // now add the nest to the stack - stack[stackPointer] = nest; - stackPointer++; - 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 + 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; -} + xmlData += value; + xmlData += ""; + return; +} // addElement + void XMLFormatter::addElement(string element, string value){ - // std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n"; - xmlData += "<"; - xmlData += element; - xmlData += ">"; - xmlData += value; - xmlData += ""; - return; -} + + if (( element != "" ) && ( value != "" )){ + xmlData += "<"; + xmlData += element; + xmlData += ">"; + xmlData += value; + xmlData += ""; + } // if + return; + +} // addElement string XMLFormatter::returnXML(){ @@ -87,14 +101,16 @@ string XMLFormatter::returnXML(){ for ( int count= stackPointer; count > 0; count-- ){ // close nest closeNest(); - } + } // if - if ( hostInfo.length() != 0 ){ - xmlData += " 0 ){ + xmlData += ""; - } + } // if - // std::cout << "DEBUG: returning XML: " << xmlData; + stackPointer = 0; + return xmlData; -} \ No newline at end of file + +} // returnXML \ No newline at end of file