Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jun 25 '10 at 20:38

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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 '10 at 20:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.