Re: [xml] How to create an ISO-8859-1 encoded xml file?

On Wed, Apr 11, 2001 at 12:13:49AM +0200, Mark Ziegler wrote:

actually I'm tring to produce a XML-file using libxml2-2.3.5:

<?xml version="1.0" encoding="ISO-8859-1"?>

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);

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

orchis:~/XML -> ./xmllint --encode ISO-8859-1 --auto
<?xml version="1.0" encoding="ISO-8859-1"?>
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 
<?xml version="1.0" encoding="ISO-8859-1"?>

  Convert them to UTF8 strings before inserting them in the tree,
you can use the isolat1ToUTF8() routine for doing so on strings.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

Attachment: encoding.patch
Description: Text document

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