[xml] Retrieve encoding from xml input document (ctxt->encoding)


I've got a little problem with libxml2 as i want to retrieve encoding
type from xml input document.

Here a little test code :

#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>

int main(int argc, char * argv[]){

        xmlParserCtxtPtr ctxt;

        ctxt = xmlCreateFileParserCtxt(argv[argc - 1]);
        if (ctxt == NULL) return EXIT_FAILURE;


        printf("[%s]\n", ctxt->version);
        printf("[%s]\n", ctxt->encoding);


        return EXIT_SUCCESS;

Compilation line :
gcc -Wall -ansi -pedantic -g `xml2-config --cflags` test.c -o test
`xml2-config --libs`

xml2-config --version -> 2.6.2

And if i launch the test program on an xml document, i retrieve
correctly the xml version number, but *not* the encoding. Except when
encoding is UTF-8. On other case (ISO-8859-1, US-ASCII...)
ctxt->encoding is a NULL pointer.

I've read doc, and several mails from this mailing list about encoding,
but none seems helpfull in this case. 

I also play with DEBUG_ENCODING from encoding.c and in all cases the
encoding handler founded is right. 

So i surely miss something, as i believe it's a common task...
Any help would be appreciate :)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]