Re: [xml] xmlSaveToFilename with UTF-8 encoding



-----Original Message-----
From: Michael Rottmeier [mailto:michael rottmeier web de] 
Sent: Thursday, April 19, 2007 1:53 PM
To: xml gnome org
Subject: [xml] xmlSaveToFilename with UTF-8 encoding

Hi,

For a current project I'm using your libxml/libxslt libraries 
which are really great.

But I have a problem with the following procedure:

-- parse an xml file with xmlParseFile()
-- parse an xsl stylesheet with xsltParseStylesheetFile()
-- create a transformation context with xsltNewTransformContext()
-- apply the stylesheet to the xml doc with xsltApplyStylesheetUser()

-- and finally save the transformation result with xmlSaveFileEnc()

The problem is that the final file is not encoded as UTF-8 as 
defined in the API call but instead it ends up with simple 
ANSI encoding. When calling xmlSaveFileEnc() I pass in 
"UTF-8" as the paramter but without any success.
The same goes for if I use xmlSaveToFilename() where the 
encoding can also be defined -- but again the final file is ANSI.

Any tips on how to make sure the file is saved as UTF-8?


        xmlInitParser();
        xmlDoc *doc = NULL;
        xmlNode *root_element = NULL;
        doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
        if(!doc)
                throw -1;
        root_element = xmlNewDocNode(doc, NULL, XMLCHARCAST("TEST_ROOT"),
NULL);
        xmlDocSetRootElement(doc, root_element);
        my_object->AppendNodes(root_element);
        xmlSaveFormatFileEnc("test_file.xml", doc, "UTF-8", 1);
        xmlFreeDoc(doc);
        xmlCleanupParser();

This does work without problem for me.
        <?xml version="1.0" encoding="UTF-8"?>
        <TEST_ROOT>
        ...
        </TEST_ROOT>
Does this problem occur always for you, even with the example files?
What encoding is written into the xml header?

best regards / mit freundlichen Grüßen,
Martin Trappel



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