Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with unicode and XML

problem with unicode and XML

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionxml
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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 "

    A 1 Reply Last reply
    0
    • L Lost User

      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 "

      A Offline
      A Offline
      Alois Kraus
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • A Alois Kraus

        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.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Thank you for your reply Alois, but I want to create the file at runtime. Regards, Christos P.

        A 1 Reply Last reply
        0
        • A Anonymous

          Thank you for your reply Alois, but I want to create the file at runtime. Regards, Christos P.

          A Offline
          A Offline
          Alois Kraus
          wrote on last edited by
          #4

          These two bytes will always be the same once You know them. Just prepend them.

          E 1 Reply Last reply
          0
          • A Alois Kraus

            These two bytes will always be the same once You know them. Just prepend them.

            E Offline
            E Offline
            Ernesto Perales Soto
            wrote on last edited by
            #5

            All unicode text files must begin with the Unicode char 0xFEFF eperales

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups