1

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>
4
  • Please narrow the scope of your question. "What should I keep in mind" is very broad and could involve numerous things. Give us something to focus on.
    – Jonathan M
    Sep 16, 2011 at 4:19
  • Sure. I used two fprintf statements in my code to print <Group> and </Group> after the xml header. Now when i open my xml using IE, i see the xml header followed by <Group\>(which is wrong), whereas any editor shows proper contents.
    – user911747
    Sep 16, 2011 at 4:22
  • What about showing some code and output? Sep 16, 2011 at 4:25
  • Please just edit your question to provide additional information, code or clarification.
    – user50049
    Sep 16, 2011 at 9:37

2 Answers 2

2

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.

1
  • Thanks!! I will try adding more nodes to my parent node(Group) and then check if IE displays correctly.
    – user911747
    Sep 16, 2011 at 4:42
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.