I have an empty line when I run your code. Are you viewing the file in the editor or parsing it and showing it? I ask because the parameters xml: space = "save" may be inconvenient in your parser code, if this is the case.
Another option is to put a comment in the root XML element itself:
final Element rootElement = doc.createElement("projects"); doc.appendChild(rootElement); rootElement.appendChild(doc.createComment(" DO NOT EDIT THIS FILE "));
In several ways, this is more compatible. For example, suppose you use xinclude to embed in the final version of a file. The way in your question, the notification that you are not editing the file, will not be included. If you put it in the root element, it will (and you probably should change it to say something about not editing the contents of this project element, and not saying the file for the same reason).
source share