TinyXML2 / C ++ - insert element
I wanted to serialize objects from XML, so I got TinyXML. However, I went with the new TinyXML2. The problem is I can't find a tutorial anywhere, so I just read the documentation. However, I seem to be stuck with adding an element to a document.
Can anyone tell me what is wrong with my code?
Here's my file content demo.xml
:
<?xml version="1.0" ?>
<Hello>World</Hello>
here's my method main()
:
#include "tinyxml2/tinyxml2.h"
using namespace tinyxml2;
int main (int argc, char * const argv[])
{
XMLDocument doc;
if (doc.LoadFile("demo.xml") == XML_SUCCESS)
{
XMLNode *node = doc.NewElement("foo");
doc.InsertEndChild(node);
doc.SaveFile("demo2.xml");
}
}
and finally, here is the file demo2.xml
:
<?xml version="1.0" ?>
<Hello>World</Hello>
<foo/>
Foo should look like this: <foo></foo>
But for some reason this is not so. Can someone explain why?
+3
source to share