diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 91f4011..59a149e 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2008,7 +2008,7 @@ void XMLPrinter::PushAttribute( const char* name, double v ) } -void XMLPrinter::CloseElement() +void XMLPrinter::CloseElement( bool compactMode ) { --_depth; const char* name = _stack.Pop(); @@ -2017,7 +2017,7 @@ void XMLPrinter::CloseElement() Print( "/>" ); } else { - if ( _textDepth < 0 && !_compactMode) { + if ( _textDepth < 0 && !compactMode) { Print( "\n" ); PrintSpace( _depth ); } @@ -2027,7 +2027,7 @@ void XMLPrinter::CloseElement() if ( _textDepth == _depth ) { _textDepth = -1; } - if ( _depth == 0 && !_compactMode) { + if ( _depth == 0 && !compactMode) { Print( "\n" ); } _elementJustOpened = false; @@ -2161,9 +2161,9 @@ bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attr } -bool XMLPrinter::VisitExit( const XMLElement& ) +bool XMLPrinter::VisitExit( const XMLElement& element ) { - CloseElement(); + CloseElement( _compactMode ? true : element.GetForceCompactMode() ); return true; } diff --git a/tinyxml2.h b/tinyxml2.h index 09f6dd2..eae8cd4 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1974,7 +1974,7 @@ public: void PushAttribute( const char* name, bool value ); void PushAttribute( const char* name, double value ); /// If streaming, close the Element. - virtual void CloseElement(); + virtual void CloseElement( bool compactMode ); /// Add a text node. void PushText( const char* text, bool cdata=false ); diff --git a/xmltest.cpp b/xmltest.cpp index 3997b64..7c24090 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1039,6 +1039,21 @@ int main( int argc, const char ** argv ) XMLTest( "Selective text wrapping", "\n Before TagTagTwo After\n\n", printer.CStr() ); } + { + XMLDocument doc0; + XMLElement* root = doc0.NewElement("root"); + doc0.InsertEndChild(root); + XMLElement* cool = doc0.NewElement("cool"); + cool->SetForceCompactMode(true); + root->InsertEndChild(cool); + XMLElement* tag = doc0.NewElement("true"); + cool->InsertEndChild(tag); + + XMLPrinter printer; + doc0.Print( &printer ); + XMLTest( "Selective text around single tag", "\n \n\n", printer.CStr() ); + } + { // Make sure an attribute with a space in it succeeds. static const char* xml0 = "";