libxml2 expects the passed encoding to be NUL terminated, so we reject strings with NUL bytes right away. Closes GH-6899.