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

Function xmlDocSetRootElement

ThirdParty/libxml2/vtklibxml2/tree.c:5082–5112  ·  view source on GitHub ↗

* xmlDocSetRootElement: * @doc: the document * @root: the new document root element, if root is NULL no action is taken, * to remove a node from a document use xmlUnlinkNode(root) instead. * * Set the root element of the document (doc->children is a list * containing possibly comments, PIs, etc ...). * * @root must be an element node. It is unlinked before insertion. * * Return

Source from the content-addressed store, hash-verified

5080 * didn't have a root element or a memory allocation failed.
5081 */
5082xmlNodePtr
5083xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) {
5084 xmlNodePtr old = NULL;
5085
5086 if (doc == NULL) return(NULL);
5087 if ((root == NULL) || (root->type == XML_NAMESPACE_DECL))
5088 return(NULL);
5089 old = doc->children;
5090 while (old != NULL) {
5091 if (old->type == XML_ELEMENT_NODE)
5092 break;
5093 old = old->next;
5094 }
5095 if (old == root)
5096 return(old);
5097 xmlUnlinkNodeInternal(root);
5098 if (xmlSetTreeDoc(root, doc) < 0)
5099 return(NULL);
5100 root->parent = (xmlNodePtr) doc;
5101 if (old == NULL) {
5102 if (doc->children == NULL) {
5103 doc->children = root;
5104 doc->last = root;
5105 } else {
5106 xmlAddSibling(doc->children, root);
5107 }
5108 } else {
5109 xmlReplaceNode(old, root);
5110 }
5111 return(old);
5112}
5113#endif
5114
5115#if defined(LIBXML_TREE_ENABLED)

Callers 3

openFileMethod · 0.85
parseFileFunction · 0.85

Calls 4

xmlUnlinkNodeInternalFunction · 0.85
xmlSetTreeDocFunction · 0.85
xmlAddSiblingFunction · 0.85
xmlReplaceNodeFunction · 0.85

Tested by

no test coverage detected