* xmlAddChild: * @parent: the parent node * @cur: the child node * * Unlink @cur and append it to the children of @parent. * * If @cur is a text node, it may be merged with an adjacent text * node and freed. In this case the text node containing the merged * content is returned. * * If @cur is an attribute node, it is appended to the attributes of * @parent. If the attribute list cont
| 3399 | * if arguments are invalid or a memory allocation failed. |
| 3400 | */ |
| 3401 | xmlNodePtr |
| 3402 | xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { |
| 3403 | xmlNodePtr prev; |
| 3404 | |
| 3405 | if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL) || |
| 3406 | (cur == NULL) || (cur->type == XML_NAMESPACE_DECL) || |
| 3407 | (parent == cur)) |
| 3408 | return(NULL); |
| 3409 | |
| 3410 | /* |
| 3411 | * If parent is a text node, call xmlTextAddContent. This |
| 3412 | * undocumented quirk should probably be removed. |
| 3413 | */ |
| 3414 | if (parent->type == XML_TEXT_NODE) { |
| 3415 | if (xmlTextAddContent(parent, cur->content, -1) < 0) |
| 3416 | return(NULL); |
| 3417 | xmlFreeNode(cur); |
| 3418 | return(parent); |
| 3419 | } |
| 3420 | |
| 3421 | if (cur->type == XML_ATTRIBUTE_NODE) { |
| 3422 | prev = (xmlNodePtr) parent->properties; |
| 3423 | if (prev != NULL) { |
| 3424 | while (prev->next != NULL) |
| 3425 | prev = prev->next; |
| 3426 | } |
| 3427 | } else { |
| 3428 | prev = parent->last; |
| 3429 | } |
| 3430 | |
| 3431 | if (cur == prev) |
| 3432 | return(cur); |
| 3433 | |
| 3434 | return(xmlInsertNode(parent->doc, cur, parent, prev, NULL, 1)); |
| 3435 | } |
| 3436 | |
| 3437 | /** |
| 3438 | * xmlGetLastChild: |
no test coverage detected