When generating am xml in C by using fprintf(), what should be kept in mind? I am using it, but i am facing some issues when opening the xml in IE; however, in any editor, it shows proper contents.
Code
int WriteXmlElement(const char* filename, const char* element, int iTextAssociated)
{
FILE *fp = NULL;
fp = fopen(filename, "a+");
if(fp != NULL)
{
fprintf(fp, "<%s>\n",element);
fprintf(fp,"</%s>\n" , element);
fclose(fp);
return 0;
}
开发者_运维知识库 else
return -1;
}
XML in IE
<?xml version="1.0" encoding="UTF-8" ?>
<Group />
XML in any editor
<?xml version="1.0" encoding="UTF-8" ?>
<Group> </Group>
The XML is being generated just fine. Internet Explorer is choosing to reinterpret it by automatically refactoring empty tags of the form <foo></foo>
into just <foo/>
for display purposes (it does not modify the file on disk). If you want to be sure that the XML file you're generating has the proper contents, just look at it in a regular text editor instead of IE.
the way you are doing is the simplest way ..but i prefer you to use http://www.minixml.org/
in your way make sure this thing 1> every node should be closed in order
2> if you are not writing anything between & then put one space between them (some browser shows error if you dont write anything between that)
精彩评论