problem with unicode and XML
-
Hi all, I am trying to create an XML file (containing Greek characters also) from within Visual C++ 6. The code is listed below: FILE *v_myfile; _TCHAR v_fileline[100]; _TCHAR v_filename[100]; swprintf(v_filename, _T("%s"), _T("myfile.xml")); v_myfile=_wfopen(v_filename, _T("w")); swprintf(v_fileline, _T("%s"), _T("")); fwrite(v_fileline, sizeof(_TCHAR), wcslen(v_fileline), v_myfile); swprintf(v_fileline, _T("%s"), _T("some text")); fwrite(v_fileline, sizeof(_TCHAR), wcslen(v_fileline), v_myfile); ....... similar writes to the file and finally.. fclose(v_myfile); Well, the file is created and I am able to view it using the notepad. However, when I am trying to open it using Internet Explorer I am getting an error related to an invalid character at position 2, line 1 (at the "<" character). If I open the file with notepad and then save the file WITHOUT making any changes (notepad automatically suggests that I save it as UNICODE), the Internet Explorer is then able to read the file correctly:wtf:. Before I save it using notepad, the length of the file is 752 bytes. After I save it, the length is 754. I guess that these two bytes make the difference. Anybody have any idea about what is happening? also, instead of "UNICODE" at the "
-
Hi all, I am trying to create an XML file (containing Greek characters also) from within Visual C++ 6. The code is listed below: FILE *v_myfile; _TCHAR v_fileline[100]; _TCHAR v_filename[100]; swprintf(v_filename, _T("%s"), _T("myfile.xml")); v_myfile=_wfopen(v_filename, _T("w")); swprintf(v_fileline, _T("%s"), _T("")); fwrite(v_fileline, sizeof(_TCHAR), wcslen(v_fileline), v_myfile); swprintf(v_fileline, _T("%s"), _T("some text")); fwrite(v_fileline, sizeof(_TCHAR), wcslen(v_fileline), v_myfile); ....... similar writes to the file and finally.. fclose(v_myfile); Well, the file is created and I am able to view it using the notepad. However, when I am trying to open it using Internet Explorer I am getting an error related to an invalid character at position 2, line 1 (at the "<" character). If I open the file with notepad and then save the file WITHOUT making any changes (notepad automatically suggests that I save it as UNICODE), the Internet Explorer is then able to read the file correctly:wtf:. Before I save it using notepad, the length of the file is 752 bytes. After I save it, the length is 754. I guess that these two bytes make the difference. Anybody have any idea about what is happening? also, instead of "UNICODE" at the "
If I remember right there are two bytes at the beginning of every Unicode text file. Just copy the two first bytes of the "correct file" in front of Your file and all will be fine.
-
If I remember right there are two bytes at the beginning of every Unicode text file. Just copy the two first bytes of the "correct file" in front of Your file and all will be fine.
-
Thank you for your reply Alois, but I want to create the file at runtime. Regards, Christos P.
These two bytes will always be the same once You know them. Just prepend them.
-
These two bytes will always be the same once You know them. Just prepend them.
All unicode text files must begin with the Unicode char
0xFEFF
eperales