My problem is that I want to create an xml tree and get a simple string object (or even char *). And I can not save xml to file.
So, at the input, I have xmlDocPtr with a full xml tree and you want to get a string containing xml, but without using files.
thanks for attention.
Use xmlDocDumpMemory or any of its cousins. Using:
void xml_to_string(xmlDocPtr doc, std::string &out) { xmlChar *s; int size; xmlDocDumpMemory(doc, &s, &size); if (s == NULL) throw std::bad_alloc(); try { out = (char *)s; } catch (...) { xmlFree(s); throw; } xmlFree(s); }
What I wrote earlier. Hope this helps ...
xmlDocPtr pDoc = ... // your xml docuemnt xmlCharPtr psOutput; int iSize; xmlDocDumpFormatMemoryEnc(pDoc, &psOutput, &iSize, "UTF-8", 1); // psOutput should point to the string. // Don't forget to free the memory. xmlFree(psOutput);
xmlDocDumpMemory(), . xmlCleanupParser() , xmlDocDumpMemory(). , xmlDocDumpMemory() .
I was not able to get exactly what you want, but after changing the value of the node, you can save easily with xmlDocDump.