Hi, I tried the code you posted, i only modified the line in which you create the XMLByte*, instead of using "()" i replaced it with "[]". (when i used the () and exception was thrown when i tried to delete the XMLByte*)
The problem i've got now, is that this code causes a memory leak.. when i tried to run it in a "while(true)" loop, it produced a serious leak. How can i fix it? And another thing, is it ok to convert an XMLByte* to char*? or is there a better way for converting and XMLByte* to a std::string? Thanks again :) David Bertoni wrote: > > The transcoder does not allocate a target buffer for transcoding. Please > make sure you read the comments for any functions you try to use: > > /** Converts from the encoding of the service to the internal XMLCh* > encoding > * > * @param srcData the source buffer to be transcoded > * @param srcCount number of bytes in the source buffer > * @param toFill the destination buffer > * @param maxChars the max number of characters in the destination > buffer > > Since you allocated a single byte, but probably passed in a larger value, > your code suffers from a buffer overrun error. The exception is probably > a > result of your code trashing some heap control information. Or perhaps > you > used "delete", instead of "delete []". > > Search the code for other uses of this functionality, because it's more > complicated than just making a single call to the transcoder, if you want > reasonable efficiency. > > If you want a simple, but potentially inefficient implementation, you can > just assume 4 bytes of UTF-8 for every byte of the input and allocate a > buffer accordingly. > > size_t len = XMLString::stringLen(text); > XMLByte* utf8 = new XMLByte((len * 4) + 1); // ? > unsigned int eaten; > unsigned int utf8Len = utf8Transcoder->transcodeTo(text, len, utf8, len * > 4, > eaten, XMLTranscoder::UnRep_Throw); > > utf8[utf8Len] = '\0'; > string str = (char*)utf8; > > delete [] utf8; > > Dave > > -- View this message in context: http://www.nabble.com/Converting-XMLCh*-to-std%3A%3Astring-with-encoding-tf4807661.html#a13817081 Sent from the Xerces - C - Users mailing list archive at Nabble.com.
