* xmlRemoveRef: * @doc: the document * @attr: the attribute * * DEPRECATED, do not use. This function will be removed from the public API. * * Remove the given attribute from the Ref table maintained internally. * * Returns -1 if the lookup failed and 0 otherwise */
| 2855 | * Returns -1 if the lookup failed and 0 otherwise |
| 2856 | */ |
| 2857 | int |
| 2858 | xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) { |
| 2859 | xmlListPtr ref_list; |
| 2860 | xmlRefTablePtr table; |
| 2861 | xmlChar *ID; |
| 2862 | xmlRemoveMemo target; |
| 2863 | |
| 2864 | if (doc == NULL) return(-1); |
| 2865 | if (attr == NULL) return(-1); |
| 2866 | |
| 2867 | table = (xmlRefTablePtr) doc->refs; |
| 2868 | if (table == NULL) |
| 2869 | return(-1); |
| 2870 | |
| 2871 | ID = xmlNodeListGetString(doc, attr->children, 1); |
| 2872 | if (ID == NULL) |
| 2873 | return(-1); |
| 2874 | |
| 2875 | ref_list = xmlHashLookup(table, ID); |
| 2876 | if(ref_list == NULL) { |
| 2877 | xmlFree(ID); |
| 2878 | return (-1); |
| 2879 | } |
| 2880 | |
| 2881 | /* At this point, ref_list refers to a list of references which |
| 2882 | * have the same key as the supplied attr. Our list of references |
| 2883 | * is ordered by reference address and we don't have that information |
| 2884 | * here to use when removing. We'll have to walk the list and |
| 2885 | * check for a matching attribute, when we find one stop the walk |
| 2886 | * and remove the entry. |
| 2887 | * The list is ordered by reference, so that means we don't have the |
| 2888 | * key. Passing the list and the reference to the walker means we |
| 2889 | * will have enough data to be able to remove the entry. |
| 2890 | */ |
| 2891 | target.l = ref_list; |
| 2892 | target.ap = attr; |
| 2893 | |
| 2894 | /* Remove the supplied attr from our list */ |
| 2895 | xmlListWalk(ref_list, xmlWalkRemoveRef, &target); |
| 2896 | |
| 2897 | /*If the list is empty then remove the list entry in the hash */ |
| 2898 | if (xmlListEmpty(ref_list)) |
| 2899 | xmlHashRemoveEntry(table, ID, xmlFreeRefTableEntry); |
| 2900 | xmlFree(ID); |
| 2901 | return(0); |
| 2902 | } |
| 2903 | |
| 2904 | /** |
| 2905 | * xmlGetRefs: |
nothing calls this directly
no test coverage detected