--- projects/cms/source/host/c++/XMLFormatter.cpp 2001/01/24 19:33:37 1.2 +++ projects/cms/source/host/c++/XMLFormatter.cpp 2001/03/23 16:38:34 1.6 @@ -2,20 +2,22 @@ XMLFormatter::XMLFormatter( string newHostInfo ){ // std::cout << "DEBUG: " << newHostInfo << "\n"; - xmlData += "<"; - xmlData += newHostInfo; - xmlData += ">"; + if ( newHostInfo != "" ){ - hostInfo = newHostInfo; - // std::cout << "DEBUG: xmldata: " << xmlData << "\n"; - + xmlData += "<"; + xmlData += newHostInfo; + xmlData += ">"; + + hostInfo = newHostInfo; + // std::cout << "DEBUG: xmldata: " << xmlData << "\n"; + } stackPointer = 0; } -XMLFormatter::XMLFormatter( ){ +XMLFormatter::XMLFormatter(){ // std::cout << "DEBUG: " << "No Root info" << "\n"; hostInfo = ""; // null - xmlData = hostInfo; + xmlData = ""; stackPointer = 0; } @@ -23,6 +25,8 @@ XMLFormatter::XMLFormatter( string newHostInfo, string // std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n"; xmlData += "<"; xmlData += newHostInfo; + xmlData += " "; + xmlData += attributes; xmlData += ">"; hostInfo = newHostInfo; @@ -32,24 +36,32 @@ XMLFormatter::XMLFormatter( string newHostInfo, string void XMLFormatter::closeNest(){ // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; - stackPointer--; - xmlData += ""; + if ( stackPointer >= 0 ){ + + stackPointer--; + xmlData += ""; + } return; } 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; } void XMLFormatter::addElement(string element, string attributes, string value){ @@ -59,23 +71,27 @@ void XMLFormatter::addElement(string element, string a xmlData += " "; xmlData += attributes; xmlData += ">"; - xmlData += value; - xmlData += ""; - return; + xmlData += value; + xmlData += ""; + + return; } 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; } @@ -87,11 +103,13 @@ string XMLFormatter::returnXML(){ closeNest(); } - if ( hostInfo.length() != 0 ){ - xmlData += " 0 ){ + xmlData += ""; } + + stackPointer = 0; // std::cout << "DEBUG: returning XML: " << xmlData; return xmlData;