Re: [xml] Query regardin storing of encoding information

On Wed, Apr 23, 2008 at 11:28:01AM +0800, Ashwin wrote:
 We store the encoding of the document as advertized in the
xml declaration in the document encoding itself.

Breakpoint 1, xmlFreeDoc (cur=0x725d98) at tree.c:1175
1175    xmlFreeDoc(xmlDocPtr cur) {
(gdb) p cur->encoding
$1 = (const xmlChar *) 0x725ed8 "ISO-8859-1"

  Suppose I am using Sax callbacks for parsing, in that case if I want to
know the encoding specified in the xml declaration, I will try to retrieve
it from ctxt->encoding, however ctxt->encoding is set to only UTF-8 or
UTF-16, depending on whichever is specified in the xml declaration. In case
the xml declaration specifies any other encoding, for instance GB2312, then
ctxt->encoding will be NULL, while ctxt->input->encoding will be set to

My doubt is in the function xmlParseEncodingDecl, ctxt->encoding is not set
to the encoding specified in the xml declaration if its not UTF-8 or

The function checks if the encoding specified in the xml declaration is
UTF-8 or UTF-16, and sets ctxt->encoding if that is the case else it sets 
ctxt->input->encoding to the encoding specified in the xml declaration while
ctxt->encoding is NULL.

Is there any specific reason for this? 

  Not that I remember. But basically if you use SAX, this means that you're
doing input only of the document, don't plan to save it and hence the 
original encoding is not useful. 
  I don't have any good explanation for not setting ctxt->encoding, this
value is checked in a number of places but I can't think right now why this
would be a problem.


Red Hat Virtualization group
Daniel Veillard      | virtualization library
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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