XML comments that are added before the document's root element either appear as a (previous) sibling of the root element or as child of the XML prolog, depending on whether one is present or not. This makes the process of detecting and creating comments at this position unnecessarily complex.
Also, In case the prolog is omitted, the comment appears before the "artificial" prolog element, though this doesn't seem to be a big problem.
See the screenshots.