[xml] how to get xmldecl encoding with SAX



Hi Daniel, All,

I'm having a trouble finding out a trace of the original encoding
declared in the <?xml ...?> decl with SAX. It seems to me it should be
visible as ctx->encoding from the startDocument event but the string
is null even if my XML file declares <?xml version='1.0'
encoding='iso-8859-2'?>.

(I know all data I get are utf8, I just need to remember the original
encoding to be able to write my output in the same encoding).

I'm actually using XML::LibXML::SAX perl interface to the SAX parser,
but the problem seems to be down in the libxml2 layer. To check this,
I've changed the textSAX.c program to print the encoding as follows:

/**
 * startDocumentDebug:
 * @ctxt:  An XML parser context
 *
 * called when the document start being processed.
 */
static void
startDocumentDebug(void *ctx ATTRIBUTE_UNUSED)
{
    callbacks++;
    if (quiet)
        return;
    fprintf(stdout, "SAX.startDocument(encoding(%s))\n",((xmlParserCtxtPtr) ctx)->encoding);
}

The result I get looks like 

SAX.setDocumentLocator()
SAX.startDocument(encoding((null)))
...

though. Any help here?

-- Petr Pajas



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