Is it OK to put comments before the XML declaration in an XML file?
<!--
Is this bad to do?
-->
<?xml version="1.0" encoding="utf-8"?>
<someElement />
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it’s not OK.
Appendix F of the XML spec says:
Ah, but, section F is non-normative, you say.
Well, section 2.1 gives the production for a well-formed XML document, thus:
…and in section 2.8 we get the production for “prolog”:
So, you can omit the < ?xml declaration, but you can’t prefix it with anything.
(Incidentally, “Misc” is the category that comments fall into).