It seems that I've got a solution to my problem with
XMLTranscoder::transcodeFrom.
It may be not the perfect one, but it works.
Hope this help.
PS: why 16x1024 for makeNewTranscoderFor ?
why max_chars = source_count * 6 ?
-------------------------------------------------------------------------------
// Compile with: g++ Test1.cpp -o Test1 -lxerces-c -Wl,-rpath
-Wl,/usr/local/lib/
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOMLSParser.hpp>
#include <xercesc/util/TransService.hpp>
using namespace XERCES_CPP_NAMESPACE;
XMLCh *
transcodeUTF16(const char * __source_data)
{
XMLTransService::Codes result_code; // result of the encoding creation:
Ok | UnsupportedEncoding | InternalFailure | SupportFilesNotFound
XMLTranscoder * transcoder =
XMLPlatformUtils::fgTransService->makeNewTranscoderFor("UTF-16",
result_code, 16*1024);
XMLSize_t source_count = strlen(__source_data);
XMLSize_t max_chars = source_count * 6 + 1;
XMLCh * output = new XMLCh[max_chars];
XMLSize_t bytes_eaten = 0;
unsigned char* char_sizes = new unsigned char[max_chars];
int nb_ret_chars = transcoder->transcodeFrom( (const XMLByte*)
__source_data, source_count, output, max_chars, bytes_eaten, char_sizes);
delete(char_sizes);
delete(transcoder);
return(output);
}
int
main(int __argc,
char* __argv[])
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& e)
{
return(-1);
}
char * value = "problem with this character: —";
// WORKING
XMLCh * transcoded_value = transcodeUTF16(value);
delete(transcoded_value);
// NOT WORKING: throw an TranscodingException because of the character
'—' !!
// XMLCh* xml_sample = XMLString::transcode(sample);
// XMLString::release(&xml_sample);
XMLPlatformUtils::Terminate();
return(0);
}
--
View this message in context:
http://old.nabble.com/TranscodingException-tp32089859p32091499.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.