* xmlAddChildList: * @parent: the parent node * @cur: the first node in the list * * Append a node list to another node. * * See xmlAddChild. * * Returns the last child or NULL in case of error. */
| 3290 | * Returns the last child or NULL in case of error. |
| 3291 | */ |
| 3292 | xmlNodePtr |
| 3293 | xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { |
| 3294 | xmlNodePtr iter; |
| 3295 | xmlNodePtr prev; |
| 3296 | int oom; |
| 3297 | |
| 3298 | if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
| 3299 | return(NULL); |
| 3300 | } |
| 3301 | |
| 3302 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| 3303 | return(NULL); |
| 3304 | } |
| 3305 | |
| 3306 | oom = 0; |
| 3307 | for (iter = cur; iter != NULL; iter = iter->next) { |
| 3308 | if (iter->doc != parent->doc) { |
| 3309 | if (xmlSetTreeDoc(iter, parent->doc) < 0) |
| 3310 | oom = 1; |
| 3311 | } |
| 3312 | } |
| 3313 | if (oom) |
| 3314 | return(NULL); |
| 3315 | |
| 3316 | /* |
| 3317 | * add the first element at the end of the children list. |
| 3318 | */ |
| 3319 | |
| 3320 | if (parent->children == NULL) { |
| 3321 | parent->children = cur; |
| 3322 | } else { |
| 3323 | prev = parent->last; |
| 3324 | |
| 3325 | /* |
| 3326 | * If cur and parent->last both are TEXT nodes, then merge them. |
| 3327 | */ |
| 3328 | if ((cur->type == XML_TEXT_NODE) && |
| 3329 | (prev->type == XML_TEXT_NODE) && |
| 3330 | (cur->name == prev->name)) { |
| 3331 | xmlNodePtr next; |
| 3332 | |
| 3333 | if (xmlTextAddContent(prev, cur->content, -1) < 0) |
| 3334 | return(NULL); |
| 3335 | next = cur->next; |
| 3336 | xmlFreeNode(cur); |
| 3337 | /* |
| 3338 | * if it's the only child, nothing more to be done. |
| 3339 | */ |
| 3340 | if (next == NULL) |
| 3341 | return(prev); |
| 3342 | cur = next; |
| 3343 | } |
| 3344 | |
| 3345 | prev->next = cur; |
| 3346 | cur->prev = prev; |
| 3347 | } |
| 3348 | while (cur->next != NULL) { |
| 3349 | cur->parent = parent; |
no test coverage detected