1

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?

2 Answers 2

2

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.

1
  • That is what I wondering that maybe it just looks at the prolog which isn't really helpful because I can encode the file in X and write Y in the prolog
    – Anonymous
    Jun 25, 2010 at 20:37
1

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.

You must log in to answer this question.