My problem is that I want to create xml tree and get a simple string object (or even char*). And I can't save xml to file.
So in the input I have xmlDocPtr with complete xml tree and want to get string containing xml but without using files.
Thx for attention.
Use xmlDocDumpMemory or any of its cousins. Usage:
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);
}
Something I wrote while ago. Hope it 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With