Provide finer control over indentation inside the XMLPrinter. You'll have to subclass it to override its standard behaviour by overwriting CompactMode().
This commit is contained in:
20
tinyxml2.cpp
20
tinyxml2.cpp
@@ -1940,17 +1940,17 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec )
|
||||
}
|
||||
|
||||
|
||||
void XMLPrinter::OpenElement( const char* name )
|
||||
void XMLPrinter::OpenElement( const char* name, bool compactMode )
|
||||
{
|
||||
if ( _elementJustOpened ) {
|
||||
SealElement();
|
||||
}
|
||||
_stack.Push( name );
|
||||
|
||||
if ( _textDepth < 0 && !_firstElement && !_compactMode ) {
|
||||
if ( _textDepth < 0 && !_firstElement && !compactMode ) {
|
||||
Print( "\n" );
|
||||
}
|
||||
if ( !_compactMode ) {
|
||||
if ( !compactMode ) {
|
||||
PrintSpace( _depth );
|
||||
}
|
||||
|
||||
@@ -2002,7 +2002,7 @@ void XMLPrinter::PushAttribute( const char* name, double v )
|
||||
}
|
||||
|
||||
|
||||
void XMLPrinter::CloseElement()
|
||||
void XMLPrinter::CloseElement( bool compactMode )
|
||||
{
|
||||
--_depth;
|
||||
const char* name = _stack.Pop();
|
||||
@@ -2011,7 +2011,7 @@ void XMLPrinter::CloseElement()
|
||||
Print( "/>" );
|
||||
}
|
||||
else {
|
||||
if ( _textDepth < 0 && !_compactMode) {
|
||||
if ( _textDepth < 0 && !compactMode) {
|
||||
Print( "\n" );
|
||||
PrintSpace( _depth );
|
||||
}
|
||||
@@ -2021,7 +2021,7 @@ void XMLPrinter::CloseElement()
|
||||
if ( _textDepth == _depth ) {
|
||||
_textDepth = -1;
|
||||
}
|
||||
if ( _depth == 0 && !_compactMode) {
|
||||
if ( _depth == 0 && !compactMode) {
|
||||
Print( "\n" );
|
||||
}
|
||||
_elementJustOpened = false;
|
||||
@@ -2146,7 +2146,9 @@ bool XMLPrinter::VisitEnter( const XMLDocument& doc )
|
||||
|
||||
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
|
||||
{
|
||||
OpenElement( element.Name() );
|
||||
const XMLElement* parentElem = element.Parent()->ToElement();
|
||||
bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
|
||||
OpenElement( element.Name(), compactMode );
|
||||
while ( attribute ) {
|
||||
PushAttribute( attribute->Name(), attribute->Value() );
|
||||
attribute = attribute->Next();
|
||||
@@ -2155,9 +2157,9 @@ bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attr
|
||||
}
|
||||
|
||||
|
||||
bool XMLPrinter::VisitExit( const XMLElement& )
|
||||
bool XMLPrinter::VisitExit( const XMLElement& element )
|
||||
{
|
||||
CloseElement();
|
||||
CloseElement( CompactMode(element) );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user