You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Dakala <da...@ymail.com> on 2011/07/19 12:33:53 UTC
TranscodingException
Hi,
I have a well known TranscodingException in my xerces code below, because of
a special hyphen character but I don't know how to resolve it.
I'm using xerces-c-3.1.1 on a Centos 5 with kernel 2.6.18.
Could you help me, please?
Thanks a lot,
Sen
-------------------------------------------------------------------------------
// 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>
using namespace XERCES_CPP_NAMESPACE;
int
main(int __argc,
char* __argv[])
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& e)
{
return(-1);
}
char * sample = "problem with this character: —";
// throws 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-tp32089859p32089859.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.
Re: TranscodingException
Posted by Dakala <da...@ymail.com>.
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.