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

Function xmlReplaceNode

ThirdParty/libxml2/vtklibxml2/tree.c:3883–3925  ·  view source on GitHub ↗

* xmlReplaceNode: * @old: the old node * @cur: the node (optional) * * Unlink the old node. If @cur is provided, it is unlinked and * inserted in place of @old. * * It is an error if @old has no parent. * * Unlike xmlAddChild, this function doesn't merge text nodes or * delete duplicate attributes. * * See the notes in xmlAddChild. * * Returns @old or NULL if arguments are invalid

Source from the content-addressed store, hash-verified

3881 * allocation failed.
3882 */
3883xmlNodePtr
3884xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) {
3885 if (old == cur) return(NULL);
3886 if ((old == NULL) || (old->type == XML_NAMESPACE_DECL) ||
3887 (old->parent == NULL)) {
3888 return(NULL);
3889 }
3890 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
3891 /* Don't call xmlUnlinkNodeInternal to handle DTDs. */
3892 xmlUnlinkNode(old);
3893 return(old);
3894 }
3895 if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) {
3896 return(old);
3897 }
3898 if ((cur->type==XML_ATTRIBUTE_NODE) && (old->type!=XML_ATTRIBUTE_NODE)) {
3899 return(old);
3900 }
3901 xmlUnlinkNodeInternal(cur);
3902 if (xmlSetTreeDoc(cur, old->doc) < 0)
3903 return(NULL);
3904 cur->parent = old->parent;
3905 cur->next = old->next;
3906 if (cur->next != NULL)
3907 cur->next->prev = cur;
3908 cur->prev = old->prev;
3909 if (cur->prev != NULL)
3910 cur->prev->next = cur;
3911 if (cur->parent != NULL) {
3912 if (cur->type == XML_ATTRIBUTE_NODE) {
3913 if (cur->parent->properties == (xmlAttrPtr)old)
3914 cur->parent->properties = ((xmlAttrPtr) cur);
3915 } else {
3916 if (cur->parent->children == old)
3917 cur->parent->children = cur;
3918 if (cur->parent->last == old)
3919 cur->parent->last = cur;
3920 }
3921 }
3922 old->next = old->prev = NULL;
3923 old->parent = NULL;
3924 return(old);
3925}
3926#endif /* LIBXML_TREE_ENABLED */
3927
3928/************************************************************************

Callers 1

xmlDocSetRootElementFunction · 0.85

Calls 3

xmlUnlinkNodeFunction · 0.85
xmlUnlinkNodeInternalFunction · 0.85
xmlSetTreeDocFunction · 0.85

Tested by

no test coverage detected