in TXmlDocument :: When using the TXMLDocument to create XML documents you might receive a nasty EOleException: This operation can not be performed with a Node of type PCDATA.
If you want the resulting XML to look "pretty" - so that each element node appears on its own line, indented appropriately to reflect its nesting in the node hierarchy, you might be adding the doNodeAutoIndent flag in the Options property of the TXMLDocument instance.
Read the full article to learn how to Fix the "This operation can not be performed with a Node of type PCDATA" when using doNodeAutoIndent
Related:

FormatXMLDoc doesn’t produce good looking XML because it doesn’t indent enough, it’s also not configurable. I would recommend instead using xmllint.exe, it produces much nicer looking XML.