clean up string parsing code a bit and improve unicode XML declaration error