I have noticed that Linux file command does not return any value if an xml file has the <?xml version="1.0" encoding="UTF-8"?> at the top. If the prolog is missing then file -i somefile.xml returns some value. Does anyone has any idea why this happens? I am basically interested in knowing the file encoding and have found file -i filename.xml to be somewhat useful, but is there anything better available on Linux to figure the encoding and charset?
|
| |||
|
feedback
|
migrated from stackoverflow.com Jun 25 '10 at 20:38
This question came from our site for professional and enthusiast programmers.
|
File relies on the signature in the magic file, it is quite certain that it is looking at the prolog only, not scanning parts of the file to keep it simple. | |||
feedback
|
|
Guessing encodings is a black art that even popular browsers can't get exactly right. I suggest you let your parser obey the XML encoding, breaking loudly if the encoding turns out to be invalid, and that you fix encoding mistakes at the source. | |||
|
feedback
|