You can also try writing the BOM, which should tell notepad and other programs about UTF-16. john
-----Original Message----- From: PARK Youngho [mailto:[email protected]] Sent: Friday, October 23, 2009 5:13 AM To: [email protected] Subject: Re: Re: Encoding problem in using XMLFormatter and LocalFileFormatTarget Dear Alberto Massari. Thank you so much for your advice. You are right. As you said, I tried to open it again with notepad with Unicode encoding option. It opens the UTF-16 text file correctly now. I thought that I didn't understand correctly how to use Xercesc classes. I have struggled with it for more than 2 months. So, now I was about giving up to use Xercesc with other encodings other than UTF-8. Thank you so so so so so much ! Youngho. ----- Original Message ----- From: Alberto Massari To: [email protected] Sent: Friday, October 23, 2009 2:37 PM Subject: Re: Encoding problem in using XMLFormatter and LocalFileFormatTarget When notepad opens a file it doesn't know which encoding has been used; have you specified the "Unicode" encoding option in the open file dialog? Alberto PARK Youngho wrote: > 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. > > __(*^.^*)__
