diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index fad9f50..17dc5ec 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -2044,7 +2044,7 @@ void XMLPrinter::PushAttribute( const char* name, double v )
}
-void XMLPrinter::CloseElement()
+void XMLPrinter::CloseElement( bool compactMode )
{
--_depth;
const char* name = _stack.Pop();
@@ -2053,7 +2053,7 @@ void XMLPrinter::CloseElement()
Print( "/>" );
}
else {
- if ( _textDepth < 0 && !_compactMode) {
+ if ( _textDepth < 0 && !compactMode) {
Print( "\n" );
PrintSpace( _depth );
}
@@ -2063,7 +2063,7 @@ void XMLPrinter::CloseElement()
if ( _textDepth == _depth ) {
_textDepth = -1;
}
- if ( _depth == 0 && !_compactMode) {
+ if ( _depth == 0 && !compactMode) {
Print( "\n" );
}
_elementJustOpened = false;
@@ -2197,9 +2197,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 3b57935..431088d 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -2020,7 +2020,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 fa9e1a4..7c24090 100644
--- a/xmltest.cpp
+++ b/xmltest.cpp
@@ -1026,12 +1026,32 @@ int main( int argc, const char ** argv )
text->InsertEndChild(tag);
XMLText* tagText = doc0.NewText("Tag");
tag->InsertEndChild(tagText);
+ tag = doc0.NewElement("tagtwo");
+ tag->SetAttribute("two", "2");
+ text->InsertEndChild(tag);
+ tagText = doc0.NewText("TagTwo");
+ tag->InsertEndChild(tagText);
XMLText* aftText = doc0.NewText(" After");
text->InsertEndChild(aftText);
XMLPrinter printer;
doc0.Print( &printer );
- XMLTest( "Selective text wrapping", "\n Before Tag After\n\n", printer.CStr() );
+ 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() );
}
{