Right encoding support - part 01

This PR is mostly about correct handling XML file encoding.

Implemented functions for XML encoding detection. Carefully following standards, trying to be fast and support non-standard and not correct situations at the same time.

When #3462 and #3467 will be merged, I'll add ability to use encoding reported by HTTP server.