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

Function xmlCopyDoc

ThirdParty/libxml2/vtklibxml2/tree.c:4661–4725  ·  view source on GitHub ↗

* xmlCopyDoc: * @doc: the document * @recursive: if not zero do a recursive copy. * * Copy a document. If recursive, the content tree will * be copied too as well as DTD, namespaces and entities. * * Returns the copied document or NULL if a memory allocation * failed. */

Source from the content-addressed store, hash-verified

4659 * failed.
4660 */
4661xmlDocPtr
4662xmlCopyDoc(xmlDocPtr doc, int recursive) {
4663 xmlDocPtr ret;
4664
4665 if (doc == NULL) return(NULL);
4666 ret = xmlNewDoc(doc->version);
4667 if (ret == NULL) return(NULL);
4668 ret->type = doc->type;
4669 if (doc->name != NULL) {
4670 ret->name = xmlMemStrdup(doc->name);
4671 if (ret->name == NULL)
4672 goto error;
4673 }
4674 if (doc->encoding != NULL) {
4675 ret->encoding = xmlStrdup(doc->encoding);
4676 if (ret->encoding == NULL)
4677 goto error;
4678 }
4679 if (doc->URL != NULL) {
4680 ret->URL = xmlStrdup(doc->URL);
4681 if (ret->URL == NULL)
4682 goto error;
4683 }
4684 ret->charset = doc->charset;
4685 ret->compression = doc->compression;
4686 ret->standalone = doc->standalone;
4687 if (!recursive) return(ret);
4688
4689 ret->last = NULL;
4690 ret->children = NULL;
4691#ifdef LIBXML_TREE_ENABLED
4692 if (doc->intSubset != NULL) {
4693 ret->intSubset = xmlCopyDtd(doc->intSubset);
4694 if (ret->intSubset == NULL)
4695 goto error;
4696 /* Can't fail on DTD */
4697 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret);
4698 }
4699#endif
4700 if (doc->oldNs != NULL) {
4701 ret->oldNs = xmlCopyNamespaceList(doc->oldNs);
4702 if (ret->oldNs == NULL)
4703 goto error;
4704 }
4705 if (doc->children != NULL) {
4706 xmlNodePtr tmp;
4707
4708 ret->children = xmlStaticCopyNodeList(doc->children, ret,
4709 (xmlNodePtr)ret);
4710 if (ret->children == NULL)
4711 goto error;
4712 ret->last = NULL;
4713 tmp = ret->children;
4714 while (tmp != NULL) {
4715 if (tmp->next == NULL)
4716 ret->last = tmp;
4717 tmp = tmp->next;
4718 }

Callers 3

parseAndPrintFileFunction · 0.85
xmlStaticCopyNodeFunction · 0.85

Calls 7

xmlNewDocFunction · 0.85
xmlStrdupFunction · 0.85
xmlCopyDtdFunction · 0.85
xmlSetTreeDocFunction · 0.85
xmlCopyNamespaceListFunction · 0.85
xmlStaticCopyNodeListFunction · 0.85
xmlFreeDocFunction · 0.85

Tested by

no test coverage detected