MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlInsertNode

Function xmlInsertNode

ThirdParty/libxml2/vtklibxml2/tree.c:3084–3169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3082}
3083
3084static xmlNodePtr
3085xmlInsertNode(xmlDocPtr doc, xmlNodePtr cur, xmlNodePtr parent,
3086 xmlNodePtr prev, xmlNodePtr next, int coalesce) {
3087 xmlNodePtr oldParent;
3088
3089 if (cur->type == XML_ATTRIBUTE_NODE)
3090 return xmlInsertProp(doc, cur, parent, prev, next);
3091
3092 /*
3093 * Coalesce text nodes
3094 */
3095 if ((coalesce) && (cur->type == XML_TEXT_NODE)) {
3096 if ((prev != NULL) && (prev->type == XML_TEXT_NODE) &&
3097 (prev->name == cur->name)) {
3098 if (xmlTextAddContent(prev, cur->content, -1) < 0)
3099 return(NULL);
3100 xmlUnlinkNodeInternal(cur);
3101 xmlFreeNode(cur);
3102 return(prev);
3103 }
3104
3105 if ((next != NULL) && (next->type == XML_TEXT_NODE) &&
3106 (next->name == cur->name)) {
3107 if (cur->content != NULL) {
3108 xmlChar *merged;
3109
3110 merged = xmlStrncatNew(cur->content, next->content, -1);
3111 if (merged == NULL)
3112 return(NULL);
3113 xmlTextSetContent(next, merged);
3114 }
3115
3116 xmlUnlinkNodeInternal(cur);
3117 xmlFreeNode(cur);
3118 return(next);
3119 }
3120 }
3121
3122 /* Unlink */
3123 oldParent = cur->parent;
3124 if (oldParent != NULL) {
3125 if (oldParent->children == cur)
3126 oldParent->children = cur->next;
3127 if (oldParent->last == cur)
3128 oldParent->last = cur->prev;
3129 }
3130 if (cur->next != NULL)
3131 cur->next->prev = cur->prev;
3132 if (cur->prev != NULL)
3133 cur->prev->next = cur->next;
3134
3135 if (cur->doc != doc) {
3136 if (xmlSetTreeDoc(cur, doc) < 0) {
3137 /*
3138 * We shouldn't make any modifications to the inserted
3139 * tree if a memory allocation fails, but that's hard to
3140 * implement. The tree has been moved to the target
3141 * document now but some contents are corrupted.

Callers 4

xmlAddNextSiblingFunction · 0.85
xmlAddPrevSiblingFunction · 0.85
xmlAddSiblingFunction · 0.85
xmlAddChildFunction · 0.85

Calls 7

xmlInsertPropFunction · 0.85
xmlTextAddContentFunction · 0.85
xmlUnlinkNodeInternalFunction · 0.85
xmlFreeNodeFunction · 0.85
xmlStrncatNewFunction · 0.85
xmlTextSetContentFunction · 0.85
xmlSetTreeDocFunction · 0.85

Tested by

no test coverage detected