我开始使用 XML 格式创建文件,为此我使用以下代码:
void xml_create_file()
{
mxml_node_t *xml;
mxml_node_t *data;
FILE *f;
xml = mxmlNewXML("1.0");
data = mxmlNewElement(xml, "setting");
data = mxmlNewElement(xml, "URL");
data = mxmlNewText(data, 0, "http://192.168.55.55");
f = fopen("/etc/share/backup.xml", "wb");
if (f==NULL) {
close(f);
printf("backup could not be written.\n");
}
else {
mxmlSaveFile(xml, f, MXML_NO_CALLBACK);
close(f);
mxmlDelete(data);
mxmlDelete(xml);
printf("backup Saved\n");
}
}
当我检查文件 /etc/share/backup.xml 时,我发现它是空的!!!
如何解决这个问题?
注意:我使用 microxml 库