Xerces XMLString::transcode null/empty reply

心不动则不痛 提交于 2019-12-24 05:04:21

问题


Xerces transcode is returning an empty string. I think it is related to locale issues, but i'm stuck.

I have this simple program:

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <string>
#include <stdio.h>

XERCES_CPP_NAMESPACE_USE
using namespace std;

int main(int argc, char* argv[])
{
 string a = "Não";
 try
 {
   XMLPlatformUtils::Initialize("pt_PT");
 } catch(const XMLException& e)
 {
   fprintf(stdout,"ERROR INITIALIZING\n");
 }
 XMLCh *auxCh3 = XMLString::transcode(a.c_str());
 fprintf(stdout,"### %s ###\n",XMLString::transcode(auxCh3));
 XMLString::release(&auxCh3);
 XMLPlatformUtils::Terminate();
 return 0;
}

And the result is:

"### ###"

If i remove the ã, the result is ok:

"### No ###"

The server's locale is defined to:

[]$ locale
LANG=pt_PT
LC_CTYPE="pt_PT"
LC_NUMERIC="pt_PT"

Which is one of the available:

[]$ locale -a|grep pt_PT
pt_PT

Thanks for your help.


回答1:


When your program starts, by default it is in "C" locale. This is defined by POSIX standard. You need to call setlocale(LC_ALL,"") (don't forget to #include <locale.h> ) , to set the locale according to system environment variables.



来源:https://stackoverflow.com/questions/25749417/xerces-xmlstringtranscode-null-empty-reply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!