On Wed, Apr 11, 2001 at 12:13:49AM +0200, Mark Ziegler wrote:
Hi, actually I'm tring to produce a XML-file using libxml2-2.3.5: <?xml version="1.0" encoding="ISO-8859-1"?> <info>abc</info> I wrote the following code for this job: void DoIt(void) { xmlDocPtr doc; xmlNodePtr n; doc = xmlNewDoc("1.0"); n = xmlNewNode(NULL, "info"); xmlNodeSetContent(n, "abc"); xmlDocSetRootElement(doc, n); xmlSaveFileEnc("test.xml",doc,"ISO-8859-1"); xmlFreeDoc(*pDoc); } But the result ist a runtime-error message: "xmlSaveFileEnc: document not in UTF8 " Why this? I think, all charactars are hold internally as UTF8?
I think I found the bug: xmlNewDoc forgot to set up the charset value of doc I added a new option to xmllint to test this kind of problems called --auto : --auto : generate a small doc on the fly I was able to reproduce the bug the following way: orchis:~/XML -> ./xmllint --encode ISO-8859-1 --auto xmlSaveFileEnc: document not in UTF8 orchis:~/XML -> after applying the small patch enclosed this solved the problem: orchis:~/XML -> ./xmllint --encode ISO-8859-1 --auto <?xml version="1.0" encoding="ISO-8859-1"?> <info>abc</info> orchis:~/XML ->
Therefore my 1. question: How to modify the code to get my "encoding=..." headline?
see enclosed patch
2. question: What to do to insert german characters in the output (to get the following result): <?xml version="1.0" encoding="ISO-8859-1"?> <info>äüö</info>
Convert them to UTF8 strings before inserting them in the tree, you can use the isolat1ToUTF8() routine for doing so on strings. Daniel -- Daniel Veillard | Red Hat Network http://redhat.com/products/network/ veillard redhat com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
Attachment:
encoding.patch
Description: Text document