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

Function xmlNodeSetDoc

ThirdParty/libxml2/vtklibxml2/tree.c:2730–2840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2728}
2729
2730static int
2731xmlNodeSetDoc(xmlNodePtr node, xmlDocPtr doc) {
2732 xmlDocPtr oldDoc;
2733 xmlDictPtr oldDict, newDict;
2734 int ret = 0;
2735
2736 /*
2737 * Remove name and content from old dictionary
2738 */
2739
2740 oldDoc = node->doc;
2741 oldDict = oldDoc ? oldDoc->dict : NULL;
2742 newDict = doc ? doc->dict : NULL;
2743
2744 if ((oldDict != NULL) && (oldDict != newDict)) {
2745 if ((node->name != NULL) &&
2746 ((node->type == XML_ELEMENT_NODE) ||
2747 (node->type == XML_ATTRIBUTE_NODE) ||
2748 (node->type == XML_PI_NODE) ||
2749 (node->type == XML_ENTITY_REF_NODE)) &&
2750 (xmlDictOwns(oldDict, node->name))) {
2751 if (newDict)
2752 node->name = xmlDictLookup(newDict, node->name, -1);
2753 else
2754 node->name = xmlStrdup(node->name);
2755 if (node->name == NULL)
2756 ret = -1;
2757 }
2758
2759 if ((node->content != NULL) &&
2760 ((node->type == XML_TEXT_NODE) ||
2761 (node->type == XML_CDATA_SECTION_NODE)) &&
2762 (xmlDictOwns(oldDict, node->content))) {
2763 node->content = xmlStrdup(node->content);
2764 if (node->content == NULL)
2765 ret = -1;
2766 }
2767 }
2768
2769 switch (node->type) {
2770 case XML_ATTRIBUTE_NODE: {
2771 xmlAttrPtr attr = (xmlAttrPtr) node;
2772
2773 /*
2774 * Handle IDs
2775 *
2776 * TODO: ID attributes should also be added to the new
2777 * document, but it's not clear how to handle clashes.
2778 */
2779 if (attr->atype == XML_ATTRIBUTE_ID)
2780 xmlRemoveID(oldDoc, attr);
2781
2782 break;
2783 }
2784
2785 case XML_ENTITY_REF_NODE:
2786 /*
2787 * Handle entity references

Callers 3

xmlSetTreeDocFunction · 0.85
xmlDOMWrapAdoptBranchFunction · 0.85
xmlDOMWrapAdoptNodeFunction · 0.85

Calls 6

xmlDictOwnsFunction · 0.85
xmlDictLookupFunction · 0.85
xmlStrdupFunction · 0.85
xmlRemoveIDFunction · 0.85
xmlGetDocEntityFunction · 0.85
xmlRemoveEntityFunction · 0.85

Tested by

no test coverage detected