[xml] Does a valid XML file require an XML declaration?

I am parsing an XML file using Sax Parser of Xerces.
Is the XML declaration <?xml version="1.0" encoding="UTF-8"?> required?

This question is related to xml xml-declaration

The answer is


Xml declaration is optional so your xml is well-formed without it. But it is recommended to use it so that wrong assumptions are not made by the parsers, specifically about the encoding used.


It is only required if you aren't using the default values for version and encoding (which you are in that example).