* xmlStaticCopyNodeList: * @node: node to copy * @doc: target document * @parent: target node (optional) * * Copy a node list. If @parent is provided, sets the parent pointer * of the copied nodes, but doesn't update the children and last * pointer of @parent. * * Returns a the copy or NULL in case of error. */
| 4391 | * Returns a the copy or NULL in case of error. |
| 4392 | */ |
| 4393 | xmlNodePtr |
| 4394 | xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { |
| 4395 | xmlNodePtr ret = NULL; |
| 4396 | xmlNodePtr p = NULL,q; |
| 4397 | xmlDtdPtr newSubset = NULL; |
| 4398 | int linkedSubset = 0; |
| 4399 | |
| 4400 | while (node != NULL) { |
| 4401 | xmlNodePtr next = node->next; |
| 4402 | |
| 4403 | #ifdef LIBXML_TREE_ENABLED |
| 4404 | if (node->type == XML_DTD_NODE ) { |
| 4405 | if (doc == NULL) { |
| 4406 | node = next; |
| 4407 | continue; |
| 4408 | } |
| 4409 | if ((doc->intSubset == NULL) && (newSubset == NULL)) { |
| 4410 | q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); |
| 4411 | if (q == NULL) goto error; |
| 4412 | /* Can't fail on DTD */ |
| 4413 | xmlSetTreeDoc(q, doc); |
| 4414 | q->parent = parent; |
| 4415 | newSubset = (xmlDtdPtr) q; |
| 4416 | } else { |
| 4417 | /* |
| 4418 | * We don't allow multiple internal subsets in a document, |
| 4419 | * so we move the DTD instead of creating a copy. |
| 4420 | */ |
| 4421 | linkedSubset = 1; |
| 4422 | q = (xmlNodePtr) doc->intSubset; |
| 4423 | /* Unlink */ |
| 4424 | if (q->prev == NULL) { |
| 4425 | if (q->parent != NULL) |
| 4426 | q->parent->children = q->next; |
| 4427 | } else { |
| 4428 | q->prev->next = q->next; |
| 4429 | } |
| 4430 | if (q->next == NULL) { |
| 4431 | if (q->parent != NULL) |
| 4432 | q->parent->last = q->prev; |
| 4433 | } else { |
| 4434 | q->next->prev = q->prev; |
| 4435 | } |
| 4436 | q->parent = parent; |
| 4437 | q->next = NULL; |
| 4438 | q->prev = NULL; |
| 4439 | } |
| 4440 | } else |
| 4441 | #endif /* LIBXML_TREE_ENABLED */ |
| 4442 | q = xmlStaticCopyNode(node, doc, parent, 1); |
| 4443 | if (q == NULL) goto error; |
| 4444 | if (ret == NULL) { |
| 4445 | q->prev = NULL; |
| 4446 | ret = p = q; |
| 4447 | } else if (p != q) { |
| 4448 | /* the test is required if xmlStaticCopyNode coalesced 2 text nodes */ |
| 4449 | p->next = q; |
| 4450 | q->prev = p; |
no test coverage detected