+static char* escapeCharactersXML(char *input_string)
+{
+ if (input_string == NULL) {
+ return NULL;
+ }
+
+ char *output_string = NULL;
+
+ // In the worst case, each character of the input_string could be a special character,
+ // Each special character can add at most 5 extra characters to the string.
+ char temp[MAXPATHLEN*6 + 1];
+ memset(temp, 0, MAXPATHLEN*6 + 1);
+
+ char *input_ptr = input_string;
+ char *temp_ptr = &temp[0];
+
+ while(*input_ptr != '\0') {
+ char c = *input_ptr;
+
+ switch (c) {
+ case '&': {
+ *temp_ptr = '&';
+ ++temp_ptr;
+ *temp_ptr = 'a';
+ ++temp_ptr;
+ *temp_ptr = 'm';
+ ++temp_ptr;
+ *temp_ptr = 'p';
+ ++temp_ptr;
+ *temp_ptr = ';';
+ ++temp_ptr;
+ break;
+ }
+
+ case '<': {
+ *temp_ptr = '&';
+ ++temp_ptr;
+ *temp_ptr = 'l';
+ ++temp_ptr;
+ *temp_ptr = 't';
+ ++temp_ptr;
+ *temp_ptr = ';';
+ ++temp_ptr;
+ break;
+ }
+
+ case '>': {
+ *temp_ptr = '&';
+ ++temp_ptr;
+ *temp_ptr = 'g';
+ ++temp_ptr;
+ *temp_ptr = 't';
+ ++temp_ptr;
+ *temp_ptr = ';';
+ ++temp_ptr;
+ break;
+ }
+
+ case '"': {
+ *temp_ptr = '&';
+ ++temp_ptr;
+ *temp_ptr = 'q';
+ ++temp_ptr;
+ *temp_ptr = 'u';
+ ++temp_ptr;
+ *temp_ptr = 'o';
+ ++temp_ptr;
+ *temp_ptr = 't';
+ ++temp_ptr;
+ *temp_ptr = ';';
+ ++temp_ptr;
+ break;
+ }
+
+ case '\'': {
+ *temp_ptr = '&';
+ ++temp_ptr;
+ *temp_ptr = 'a';
+ ++temp_ptr;
+ *temp_ptr = 'p';
+ ++temp_ptr;
+ *temp_ptr = 'o';
+ ++temp_ptr;
+ *temp_ptr = 's';
+ ++temp_ptr;
+ *temp_ptr = ';';
+ ++temp_ptr;
+ break;
+ }
+ default: {
+ *temp_ptr = c;
+ ++temp_ptr;
+ }
+ }
+ ++input_ptr;
+ }
+
+ output_string = strdup((const char *)(&temp));
+ return output_string;
+}
+