Add compact mode to XMLPrinter, for printing without '\n' and space.
let output file smaller.
usage:
//------------------------------------------------
XMLPrinter printer;
printer->SetCompactMode( true ); //enable compact mode
doc->Print( &printer );
SomeFunction( printer.CStr() );
//------------------------------------------------
or
//------------------------------------------------
//enable at construction
XMLPrinter printer( file, true ); // to file
//XMLPrinter printer( NULL, true ); // to men
doc->Print( &printer );
SomeFunction( printer.CStr() );
//------------------------------------------------
The '\n' and space in Text or Attribute will be kept.
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 80dfc5c..1fbf8aa 100644
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -1501,13 +1501,14 @@
}
-XMLPrinter::XMLPrinter( FILE* file ) :
+XMLPrinter::XMLPrinter( FILE* file, bool compact ) :
elementJustOpened( false ),
firstElement( true ),
fp( file ),
depth( 0 ),
textDepth( -1 ),
- processEntities( true )
+ processEntities( true ),
+ compactMode( compact )
{
for( int i=0; i<ENTITY_RANGE; ++i ) {
entityFlag[i] = false;
@@ -1627,7 +1628,7 @@
}
stack.Push( name );
- if ( textDepth < 0 && !firstElement ) {
+ if ( textDepth < 0 && !firstElement && !compactMode ) {
Print( "\n" );
PrintSpace( depth );
}
@@ -1689,7 +1690,7 @@
Print( "/>" );
}
else {
- if ( textDepth < 0 ) {
+ if ( textDepth < 0 && !compactMode) {
Print( "\n" );
PrintSpace( depth );
}
@@ -1698,7 +1699,7 @@
if ( textDepth == depth )
textDepth = -1;
- if ( depth == 0 )
+ if ( depth == 0 && !compactMode)
Print( "\n" );
elementJustOpened = false;
}
@@ -1734,7 +1735,7 @@
if ( elementJustOpened ) {
SealElement();
}
- if ( textDepth < 0 && !firstElement ) {
+ if ( textDepth < 0 && !firstElement && !compactMode) {
Print( "\n" );
PrintSpace( depth );
}
@@ -1748,7 +1749,7 @@
if ( elementJustOpened ) {
SealElement();
}
- if ( textDepth < 0 && !firstElement) {
+ if ( textDepth < 0 && !firstElement && !compactMode) {
Print( "\n" );
PrintSpace( depth );
}
@@ -1762,7 +1763,7 @@
if ( elementJustOpened ) {
SealElement();
}
- if ( textDepth < 0 && !firstElement ) {
+ if ( textDepth < 0 && !firstElement && !compactMode) {
Print( "\n" );
PrintSpace( depth );
}