mirror of https://github.com/AxioDL/tinyxml2.git
SetForceCompactMode() now also handles case of a single tag inside another correctly.
This commit is contained in:
parent
15354f88c3
commit
ca412e87f2
10
tinyxml2.cpp
10
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
15
xmltest.cpp
15
xmltest.cpp
|
@ -1039,6 +1039,21 @@ int main( int argc, const char ** argv )
|
|||
XMLTest( "Selective text wrapping", "<root>\n <text>Before <tag>Tag</tag><tagtwo two=\"2\">TagTwo</tagtwo> After</text>\n</root>\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", "<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\"/>";
|
||||
|
|
Loading…
Reference in New Issue