processingInstruction() in contentHandler never gets called?

A general discussion forum.
Posts: 6
Joined: 21 Apr 2008, 10:00

processingInstruction() in contentHandler never gets called?

Postby quirxi123 » 09 May 2008, 11:50


have got a problem that I am not able to solve by myself, so I hoped that someone here in this forum can give me some advice...

The problem is following:

There is a class that is derived from XML ContentHandler and reacts to the various startElement/endElements events.
Since I need to know the encoding of the XML file that is beeing parsed I tried to override
processingInstruction() in order to get the encoding string:

Code: Select all

(void processingInstruction(const XMLString& target, const XMLString& dat))

But the problem is that this method never gets called ?!
Do I have forgotten/overseen something ?
Probably I have to set a flag or something else in order to make this work?

thanks and regards,

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: processingInstruction() in contentHandler never gets called?

Postby guenter » 09 May 2008, 13:56

The XML declaration is not a Processing Instruction (despite the similarity in syntax), so the processingInstruction() member function from your content handler won't be called.

There is currently no way to find out the document's encoding by asking the XML parser. However, the underlying expat parser could provide this information (via the XML_XmlDeclHandler callback).

The way to implement this properly is to implement the SAX2 ext Locator2 interface, which has getXMLVersion() and getEncoding() methods. Doing that should not be too hard.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest