Is it necessary to do that ? What purpose does it serve besides telling which version of XML is used by that file ? I also read that some programs need to parse xml. So, I guess that these programs need to know the version. Is there any other reason ?
2 Answers
Is it necessary to do that ?
If you don't then the default applies. The default is usually fine. See also XML New Version - New Features
What purpose does it serve besides telling which version of XML is used by that file ?
None.
I also read that some programs need to parse xml.
XML wouldn't be useful is nothing ever parsed it.
XML version is a part of XML header line, like:
<?xml version="1.0" encoding="ISO-8859-1"?>
According to standard it is optional, so you don't need to specify it (your XML will be well formed even without this line), but in this case parser will do some assumptions. As for the version - right now it is not so important, but you should remember that if your XML document does not conform to the version specified then your document has an error. So in future when new features will be introduced this document can be invalid, because the default version for parser will be the latest version.

- 64
- 3
-
The default version is 1.0. The latest version is 1.1. The specification says [XML 1.1 documents MUST begin with an XML declaration which specifies the version of XML being used](http://www.w3.org/TR/xml11/#sec-prolog-dtd) precisely so that XML 1.0 documents which omit the version information won't be treated as 1.1 documents. – Quentin Dec 07 '12 at 20:46