Linux/Unix doesn't store information about file type, unlike some OS's. All files are just sequences of bytes to Linux. Determining the type of file is a fairly complex process where often the file has to be opened and read to scan for "magic" that identifies the file type, such as
Java's infamous hex
string "0xCAFEBABE" in classfiles. Which is what the "file" program is all about.
While XML files carry the character set encoding in the first line, many file types do not, and the best that can be done is to scan the whole file and make a guess. Which can take a lot of resources, so it isn't done as a matter of course.