On 2/16/2010 9:55 PM, [email protected] wrote:
Hi

I am using SAX2XMLReader class in Xerces 2.8 for scanning and validating
certain data fields in an XML document.

My code involves a class which is derived from DefaultHandler and
overriding the startElement. stopElement and characters callback
functions for capturing and analyzing the data.

Everything works perfectly for my except that I have a XML element which
value is in Chinese. So when the DefaultHandler::characters callback API
is invoked I need to store those Chinese characters to the C++
std::string format. For this purpose I use the XMLString::transcode
function.

void MyDefaultHandler::characters(const XMLCh* const chars,const
unsigned int length)
{
     //update the value/data of the attribute

     char * tempattr_val = (char *)XMLString::transcode(chars);
This cast is not necessary.

     m_value = string( tempattr_val );
There's no need to create a temporary string object, since std::string::operator=() support assignment with const char*.

    m_value = tempattr_val;

     XMLString::release(&tempattr_val);
}

But after running the application with an XML document containing the
Chinese characters , I realized that the transcode( ) API returns a
blank empty string . With English characters it works fine but somehow I
am unable to retain those Chinese characters.

Any help will be greatly appreciated
You are misunderstanding what the XMLString:transcode() function does. There are numerous posts regarding this problem in the archives of the mailing list.

In short, please don't use XMLString::transcode(). Instead use a UTF-8 transcoder or just keep the data in UTF-16.

Dave

Reply via email to