[xml] UTF-8 Encoding



Using libxml2-2.4.21 i found a problem concerning UTF-8 Encoding.

Maybe i am wrong, but i think there is a problem in
encoding more than one character with a higher ASCII
than 0x80.
By the way, the special characters get encoded correctly.

In the example i am trying to encode the ascii characters 0xa1 and 0xa3.

I would expect something like:

<title>&#161;&x163</title>

but i get:

<title>&#161;¡£</title>

Can anyone tell me, if i have to do the UTF encoding by myself before
adding content to a node? 


thanks.

hendrik sticher
orga kartensysteme gmbh / paderborn (germany)



short example source:

#include <stdio.h>
#include <libxml/parser.h>

int main()
{
    xmlDocPtr doc;
    xmlNodePtr tree, subtree;

    xmlChar *xmlString;
    int len;

    char test[] = "\xa1\xa3";

    doc = xmlNewDoc("1.0");
    doc->children = xmlNewDocNode(doc, NULL, "EXAMPLE", NULL);
    xmlSetProp(doc->children, "prop1", "gnome is great");
    xmlSetProp(doc->children, "prop2", "& linux too");
    tree = xmlNewChild(doc->children, NULL, "head", NULL);
    subtree = xmlNewChild(tree, NULL, "title", test);
    tree = xmlNewChild(doc->children, NULL, "chapter</abc>1", NULL);
    subtree = xmlNewChild(tree, NULL, "title", "The < Linux adventure");
    subtree = xmlNewChild(tree, NULL, "p", "bla bla bla ...");
    subtree = xmlNewChild(tree, NULL, "image", NULL);
    xmlSetProp(subtree, "href", "linus.gif");

    xmlDocDumpFormatMemoryEnc(doc,&xmlString,&len,NULL,1);
    printf("%s", xmlString); 

  return 0;
}


________________________________________________________________
Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! 
Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=13





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