Re: [xml] Charset trouble

Hi Abylai,

"Abylai Ospan" <aospan netup ru> wrote:

I have problem with charsets again ;-(
I'm add in c++
sub_subtree = xmlNewChild(subtree, NULL,(xmlChar*)

but following error ocure when mstring in KOI8-R charset:

output conversion failed due to conv error
Bytes: 0xC0 0xE1 0xFB 0xEB

As Daniel already pointed out, you have to convert to UTF-8 yourself.
This is totally independent on the output encoding you specify.

As you are on C++, there is a painless, stylistically pleasant
way to never forget the conversion: Put it in the stdcpp string to
char const* conversions.

I don't know if one of the publicly available libxml C++ does
this already, but I use it myself and I suspect others as

Something along the lines of:

typedef xmlChar const *pxmlChar;
class XmlChar: public string {
        static char const runtimecharset [];
        XmlChar (string const &s):  {
                convert (s, runtimecharset, *this, "UTF-8");
        operator  pxmlChar () const {return (pxmlChar) c_string ();}

sub_subtree = xmlNewChild (subtree, NULL,
        XmlChar ("param_value"), XmlChar (mstring)

Peter Jacobi

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]