Re: [xml] libxml vs stl



On 11/22/05, Jim <jimdon gmail com> wrote:
When dealing with inputs from libxml i would like to use a stl string
like class ...

Is this a good idea?

Depends on many things...

Is there a class that supports wide strings in C++ stl?

std::wstring

But be aware: std::wstring is string of wchar_t, when libxml2 uses simple
char (unsigned char if more preciously).  Therefore, wide strings are have
nothing with libxml2.  Also, please, pay attantion that libxml2 uses UTF-8
(multi-byte encoding) internally, therefore you unable to obtain, e.g. 4th
character by accessing to the 4th byte (i.e. str[3]) -- number of characters
and number of bytes are two different things in the UTF-8.

You can use regular std::string here (but casting from the
"unsigned char" to the "char" will be required sometimes).

Or you can use some C++ wrapper around libxml2 if you want
(e.g. libxml++, http://libxmlplusplus.sourceforge.net/ )

Again: libxml2 uses "narrow" characters (unsigned char), not a "wide"
characters (wchar_t).

Or am i better using the provide string functions in libxml?

Again, depends on your application and your personal taste.

--
Andrew W. Nosenko <andrew w nosenko gmail com>



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