how to save XML to a file (filename.xml) u

2019-09-09 09:08发布

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 !

1条回答
forever°为你锁心
2楼-- · 2019-09-09 10:02

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

查看更多
登录 后发表回答