c - Writing cyrillic characters into an xml file -
I use xmltextwriter
to write some code using libxml2
I'm having files And I have to write them to Cyrillic characters. I do it like this:
xmlTextWriterStartDocument (author, NULL, "utf-8", NULL); ... snprintf (buf, sizeof (buf), "% s", "тест"); XmlTextWriterWriteAttribute (Author, (const xmlChar *) "test_attribute", (const xmlChar *) buf);
But when I open the resulting XML file, I see the HTML rendition of my code: test_attribute = "& # x442; & amp; ; # X435; & # X441; & # x442; "
How can I fix this?
You need to use a different YT-8 encoder.
Your text in snprintf () is in CP-1251 (single-byte ASCII-Era encoding), UTF-8 (not variable-in-native encoding).
See this link for contextual implementation:
The comments are in Russian, but you only have one conversion table and
string convert toUtf8 (const char * Chars, int len)
At the end of the ceremony.
Used when you used "тест" string "РўРчС_С" "(meaningless) while encoded.
Old C code from an old project. This is CP-866 encoding (MS-DOS Uses another "popular" encoding), but the conversion from CP-1251 is straightforward.
/// CPT686 from UTF-8 characters * Dossstrough (four * buffer, cons while * Dossist) {char * buf1 = buffer; while (* dosstr) {if ((* dosstr> 127) & amp; (* dosstr & lt; 176)) {* buf1 = 208; buf1 ++; * Buf1 = (Four) (* dosstr + 16); dosstr ++; buf1 ++; continue;} if ((* dos Str> 223) & amp; (* dosstr & lt; 240)) {* buf1 = 209; buf1 ++; * Buf1 = (four) (* dosstr-96); dosstr ++; buf1 ++; released Stay;} if (* dosstr == 240) {* buf1 = 208; buf1 ++; * buf1 = 129; dosstr ++; buf1 ++; continue;} if (* dosstr == 241) {* buf1 = 209; buf1 ++; * Buf1 = 145; dosstr ++; buf1 ++;} * Buf1 = * dosstr; buf1 ++; dosstr ++;} * Buf1 = '\ 0'; return (buffer);} / // CP1251 to CP 866 Care * Winstrotods (four * buffer) {four * ptr = buffer; while (* ptr! = '\ 0') {if ((* ptr> = 0x80 + 0x40) & amp; amp; (+ ptr <0xAF + 0x40)) * ptr = (char) (* ptr-0x40); If ((* ptr> = 0xE0 + 0x10) & amp; amp; (* ptr <0xEF + 0x10)) * ptr = (four) (* ptr-0x10); If (* ptr == 0xA8) * ptr = 0xF0; If (* ptr == 0xB8) * ptr = 0xF1; Ptr ++; } Return (buffer); }
Just beware of memory.
Comments
Post a Comment