Hi im trying to add a subchild to my XML generated file. I've been reading through the manual and I can't quite figure out how to add it in my C++ code. Any ideas ?
Current code:
#include <Tinyxml.h>
TiXmlDocument doc;
TiXmlElement* msg;
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "myroot" );
doc.LinkEndChild( root );
TiXmlElement * msgs = new TiXmlElement( "parent" );
root->LinkEndChild( msgs );
msg = new TiXmlElement( "child" );
msg->LinkEndChild( new TiXmlText( "Welcome to my child" ));
msgs->LinkEndChild( msg );
doc.SaveFile( "tree.xml" );
Current output:
<?xml version="1.0" ?>
<myroot>
<parent>
<child>Welcome to my child</child>
</parent>
</myroot>
desired xml file:
<?xml version="1.0" ?>
<myroot>
<parent>
<child>Welcome to child
<subchild>Welcome to my child2</subchild>
</child>
</parent>
</myroot>
You can just repeat those lines:
So, e.g. in a loop:
Full Demo
Result:
UPDATE
To the comment:
Result: