title: libxml2 in C++, how to set encoding
body: <p>I am creating a xml document using libxml2 in C++. After xml file is created, i am seeing the following line in the top of the xml buffer. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  </code></pre>
  
  <p>I have not specified any encoding while creating the doc. Some of the xml content  ascii value is greater than 127 which is not handled by ISO-8859-1 encoding. For e.g: I have pound character <strong>(£)</strong> in my xml content. So whenever it encounters ascii value greater than 127 it breaks and my xml file is incomplete. I read from some forums saying that changing the encoding to UTF-8 will handle this kind of scenarios. But I don't know how to specify encoding for the xml doc creation. Following is the sample code I have used.</p>
  
  <pre><code>xmlDoc *doc = NULL;
  xmlChar *xmlbuff = NULL;
  int buffersize;
  xmlNodePtr pNode;
  doc = xmlNewDoc(NULL);
  pNode = xmlNewNode(0, (const xmlChar*)"Temp");
  xmlDocSetRootElement(doc, pNode);
  xmlSetProp(pNode, (const xmlChar*)"Item", (const xmlChar*)"Office£");
  xmlDocDumpMemory(doc, &amp;xmlbuff, &amp;buffersize);
  xmlFree(xmlbuff);
  xmlFreeDoc(doc);
  doc = NULL;
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;Temp Item="Office
  </code></pre>