SetForceCompactMode() now also handles case of a single tag inside another correctly.
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 91f4011..59a149e 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -2008,7 +2008,7 @@
}
-void XMLPrinter::CloseElement()
+void XMLPrinter::CloseElement( bool compactMode )
{
--_depth;
const char* name = _stack.Pop();
@@ -2017,7 +2017,7 @@
Print( "/>" );
}
else {
- if ( _textDepth < 0 && !_compactMode) {
+ if ( _textDepth < 0 && !compactMode) {
Print( "\n" );
PrintSpace( _depth );
}
@@ -2027,7 +2027,7 @@
if ( _textDepth == _depth ) {
_textDepth = -1;
}
- if ( _depth == 0 && !_compactMode) {
+ if ( _depth == 0 && !compactMode) {
Print( "\n" );
}
_elementJustOpened = false;
@@ -2161,9 +2161,9 @@
}
-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 @@
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
@@ -1040,6 +1040,21 @@
}
{
+ 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", "<root>\n <cool><true/></cool>\n</root>\n", printer.CStr() );
+ }
+
+ {
// Make sure an attribute with a space in it succeeds.
static const char* xml0 = "<element attribute1= \"Test Attribute\"/>";
static const char* xml1 = "<element attribute1 =\"Test Attribute\"/>";