XML :: Delphi's TXmlDocument component can be used to either read (and process) an existing XML document or to construct a new, empty XML document.
Unfortunately, Delphi's implementation of the TXMLDocument component, which basically uses Microsoft XML parser by default, does not provide a way to add a node of the "ntDocType" (TNodeType type).
Read the full article for a Neat trick to add !DocType and ?XML to the TXmlDocument
Related: Exporting a TreeView to XML. Populating a TreeView from XML | Work with dynamically created TXMLDocument | Reading and Manipulating XML files (RSS feeds) with Delphi

Well… article is confusing… not to say funny.
Even if the name is “How to Create the “!DocType” and “?XML” Elements using TXmlDocument”, in article this achieved using TStringList.
So what TXMLDocument has to do with it?
@Alex: Well when you need to create XML you *would* use TXMLDocument – not TStringList. But if you need to add ““!DocType” or ““?XML” to that XML, you can do it if you cheat using TStringList. Therefore TXMLDocument to create XML, TStringList to add non supported nodes.