detect encoding and trim invalid characters before parsing xml (#60)