[xsd-users] A Question about Unicode Character

Boris Kolpackov boris at codesynthesis.com
Mon Apr 14 03:45:17 EDT 2008


Hi,

kun lv <lvkun2006 at gmail.com> writes:

>     xml_schema::namespace_infomap map;
>     Param param;
>     param.arg1( L"??" );    // ?? is a chinese character means me
>     stringstream ossparam;
>     Param_(ossparam,param,map,ENCODING,xml_schema::flags::no_xml_declaration
> );
>     string strParam( ossparam.str() );
>
>  When i run this code, the content of strParam is
> <Param>
>  <arg1>???/arg1>
> </Param>

What is the ENCODING argument in the call to Param_? You should
understand that the resulting XML can be encoded using different
character encodings. If it is, say, UTF-8 then you can treat the
resulting XML as string and your Chinese character will be encoded
as a multi-byte sequence. If, however, you specify, say UTF-32 as
the encoding then the resulting XML cannot be treated as a string
-- it will most likely have '\0' bytes all over it.

So before you figure out how to convert your XML fragment to
std::wstring, you need to decide which character encoding you
want your XML to be.

Boris




More information about the xsd-users mailing list