Re: Always reports utf-8 encoding?

Franky Braem <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
Karl Waclawek wrote:
> Maybe you can post a small self-contained example program that shows 
> the problem.
>
> Karl
>
The following is a small example:

#include "expat.h"

XML_Char buffer[1000];
int length = 0;


void EndElementHandler(void *userData,
                       const XML_Char *name);

void CharacterDataHandler(void *userData,
                          const XML_Char *s,
                          int len);

int _tmain(int argc, _TCHAR* argv[])
{
    XML_Parser parser = XML_ParserCreate(NULL);
    XML_SetUserData(parser, NULL);
    XML_SetElementHandler(parser, NULL, EndElementHandler);
    XML_SetCharacterDataHandler(parser, CharacterDataHandler);

    FILE *f = fopen("c:\\temp\\modules.xml", "r");
    if ( f )
    {
      // obtain file size.
      fseek (f , 0 , SEEK_END);
      long lSize = ftell (f);
      rewind (f);

      // allocate memory to contain the whole file.
      char *readbuffer = (char*) malloc (lSize);
      if (readbuffer == NULL) exit (2);

      // copy the file into the buffer.
      fread (readbuffer,1,lSize,f);
      XML_Parse(parser, readbuffer, lSize, 1);
      free(readbuffer);
    }
    XML_ParserFree(parser);

    return 0;
}

void EndElementHandler(void *userData,
                       const XML_Char *name)
{
    length = 0;
}

void CharacterDataHandler(void *userData,
                          const XML_Char *s,
                          int len)
{
    for(int i = 0; i < len; i++, length++)
    {
        buffer[length] = s[i];
    }
}

The following is defined:

WIN32;_DEBUG;_CONSOLE;XML_UNICODE;XML_STATIC

And I link with libexpatwMT.lib

When I debug the above, the name of the tags are always readable, while 
I expect some UTF-16 characters.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.