简体   繁体   中英

how to save XML to a file (filename.xml) using libxml2 ?

I've configured libxml2 with " --with-minimum -with--schemas " switches (configuration options). I am using "xmlNewNode" "xmlAddChild" etc. functions to generate the XML file. Now, i want to save the XML to a file, but i didn't find any function to do that.

Of-course, there are plenty of functions (like xmlSaveFile() etc..) in "libxml2 full version" BUT as i said i've configured it with --minimum configuration option (b/c of memory constraints).

Any one with help ? Thanks !

xmlDocDumpMemory will let you get the whoe xml doc as a xmlChar*
xmlChar *xmlbuff;
int buffersize;
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);

after which you can save it as a file using
FILE *fp;
fp = fopen(file, "w+");
if(!fp){
printf("Could not open file for writing\\n");
return;
}
fprintf(fp, buf);
fclose(fp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM