Hi, there.
I am using Xercesc 3.0.1.
I have encoding problem in using XMLFormatter and LocalFileFormatTarget. If I
use UTF-8, everything is fine. However, if I use UTF-16, it appears that
alphanumeric characters were written fine but Korean characters were not
properly written. With XMLFormatter and LocalFileFormatTarget, I tried to
write a file with string "ABC123하늘". "하늘" is Korean string. The file written
with UTF-8 was alright when I open it with Notepad. But, the file written with
UTF-16 was not found correct when I open it with Notepad. "A B C 1 2 3 X? "
was written instead of "ABC123하늘".
Don't I know something that I have to know?
The code is as follows.
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <xercesc/framework/XMLFormatter.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
using namespace xercesc;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
XMLPlatformUtils::Initialize();
LocalFileFormatTarget* pTarget = new
LocalFileFormatTarget(L"testUTF16.txt");
XMLFormatter* pFormatter = new XMLFormatter(L"UTF-16LE", pTarget);
*pFormatter << XMLFormatter::NoEscapes << L"ABC123하늘";
pTarget->flush();
delete pFormatter;
delete pTarget;
pTarget = new LocalFileFormatTarget(L"testUTF8.txt");
pFormatter = new XMLFormatter(L"UTF-8", pTarget);
*pFormatter << XMLFormatter::NoEscapes << L"ABC123하늘";
pTarget->flush();
delete pFormatter;
delete pTarget;
XMLPlatformUtils::Terminate();
return 0;
}
Thanks.
Youngho.
__(*^.^*)__