Dev:Source/Development/Projects/Blender File Format/XML/MiscFunctions

提供: wiki
< Dev:Source‎ | Development‎ | Projects‎ | Blender File Format‎ | XML
2010年4月3日 (土) 21:01時点におけるwiki>Terrywallworkによる版
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

XMLMiscFunctions

/* Misc Tool functions */
static void generate_xml_string(xml_object *tag, char *string)
{ char *tagName; char *tagContent; char *propertyName; char *propertyValue; char *tagStart; char *tagEnd;  xml_object *child;  /* initialize the memory for our string if its not been done yet */ if (!string)  string = calloc(1, sizeof(char));   int stringSizeNew = strlen(string); int stringSizeOld = strlen(string); tagStart = "<";   /* test for children */ if (tag->child_list.first) { child = tag->child_list.first;  while (tag) { tagName = tag->tagName; tagContent = tag->content; tagEnd = " >";  /* get the size of the string needed to    hold the start tag for this xml element */ stringSizeNew = stringSizeOld + strlen(tagName) + strlen(tagContent) + strlen(tagStart) + strlen(tagEnd) + 3;  string = realloc(string, stringSizeNew); strcat(string, tagStart); strcat(string, tagName); strcat(string, tagEnd);  stringSizeOld = stringSizeNew;  generate_xml_string(child, string);  tagEnd = " />";  stringSizeNew = stringSizeOld + strlen(tagName) + strlen(tagContent) + strlen(tagStart) + strlen(tagEnd) + 3;  string = realloc(string, stringSizeNew); strcat(string, tagStart); strcat(string, tagName); strcat(string, tagEnd);  stringSizeOld = stringSizeNew;   tag = tag->next; } } else { tagName = tag->tagName; tagContent = tag->content; tagEnd = " />";  stringSizeNew = stringSizeOld + strlen(tagName) + strlen(tagContent) + 4;  string = realloc(string, stringSizeNew); strcat(string, tagStart); strcat(string, tagName); strcat(string, tagEnd);  tag = tag->next;  }
}

int XML_free_doc(xml_doc *doc)
{ if (XML_remove_tag(doc, doc->root)) { MEM_freeN(doc); return 1; } else { return 0; }
}

void XML_free_string(char *string)
{ free(string);
}

char *XML_write_string(xml_doc *doc)
{ /* start with the root tag and follow binary tree recursively  Blender's guardedalloc system does not allow for memory reallocaton so will have to use standard C library functions to build the string.*/ char *string; char *xmlStart = "<?xml version='1.0' ?>";  string = calloc(strlen(xmlStart), sizeof("char")); strcat(string, xmlStart);  generate_xml_string(doc->root, string);  return string;
}

-- DeveloperWikiJeremyWall - 11 Feb 2005