void XMLElement::setAttributes(const XMLAttr & attrs) const { xmlNode *attrNode = attrs.getElement().getRealNode(); if (node != attrNode) { xmlFreePropList(node->properties); node->properties = 0; xmlCopyPropList(node, attrNode->properties); } }
bool xml_snk_element_break(xmlNodePtr element, xml_snk_element_create_fn *create_start, xml_snk_element_create_fn *create_end) { xmlNodePtr sibling; xmlNodePtr child; xmlNodePtr next_child; xmlAttrPtr prop; xmlAttrPtr last_prop; assert(element != NULL); assert(element->parent != NULL); /* If starting element is NOT requested */ if (create_start == NULL) sibling = element; else { /* Create starting element */ sibling = create_start(element->doc, element->ns); if (sibling == NULL) return false; /* Add it right after the original one */ sibling = xmlAddNextSibling(element, sibling); if (sibling == NULL) return false; /* Copy original element's property list, if not empty */ if (element->properties != NULL) { prop = xmlCopyPropList(sibling, element->properties); if (prop == NULL) return false; /* * Attach copied property list to the created element property * list. */ if (sibling->properties == NULL) sibling->properties = prop; else { /* Find the last property */ for (last_prop = sibling->properties; last_prop->next == NULL; last_prop = last_prop->next); last_prop->next = prop; prop->prev = last_prop; } } } /* For each child of the original element */ for (child = element->children; child != NULL; child = next_child) { /* Remember next child before this one is unlinked */ next_child = child->next; /* Move the child after the new element */ sibling = xmlAddNextSibling(sibling, child); if (sibling == NULL) return false; } /* If ending element is requested */ if (create_end != NULL) { /* Create ending element */ sibling = create_end(element->doc, element->ns); if (sibling == NULL) return false; /* Add it right after the contents */ sibling = xmlAddNextSibling(element, sibling); if (sibling == NULL) return false; } /* Unlink original element */ xmlUnlinkNode(element); /* Free original element */ xmlFreeNode(element); return true; }