Fixed XML character encoding conversion.

Strangely, on Yosemite, CFStringGetCStringPtr() stops working and always returns NULL whatever the encoding given.
Here comes the patch to fix this and add better error checking.