Home > Net >  Why does TinyXml2 put XMLDeclaration at the end?
Why does TinyXml2 put XMLDeclaration at the end?

Time:10-20

I'm using TinyXml2 v8.0.0 to create an XML buffer to send to an API. The example includes a declaration. I'm implementing this with:

XMLDocument doc;
doc.InsertEndChild(doc.NewDeclaration());
XMLElement* pRoot = doc.NewElement("Stuff");
doc.InsertFirstChild(pRoot);

The documentation for NewDeclaration states:

If the 'text' param is null, the standard declaration is used.:

`<?xml version="1.0" encoding="UTF-8"?>`

You can see this as a test in https://github.com/leethomason/tinyxml2/blob/master/xmltest.cpp#L1637

But when I print the buffer out the declaration has been placed at the end of the buffer after a newline:

<Stuff>
</Stuff>

<?xml version="1.0" encoding="UTF-8"?>

Does anyone know why this is happening? I'd expect it to be at the start of the buffer with no newline.

CodePudding user response:

Presumably, that's because you told it to put the declaration as the EndChild and the Stuff element as the FirstChild.

  • Related