* xmlFreeDocElementContent: * @doc: the document owning the element declaration * @cur: the element content tree to free * * Free an element content structure. The whole subtree is removed. */
| 912 | * Free an element content structure. The whole subtree is removed. |
| 913 | */ |
| 914 | void |
| 915 | xmlFreeDocElementContent(xmlDocPtr doc, xmlElementContentPtr cur) { |
| 916 | xmlDictPtr dict = NULL; |
| 917 | size_t depth = 0; |
| 918 | |
| 919 | if (cur == NULL) |
| 920 | return; |
| 921 | if (doc != NULL) |
| 922 | dict = doc->dict; |
| 923 | |
| 924 | while (1) { |
| 925 | xmlElementContentPtr parent; |
| 926 | |
| 927 | while ((cur->c1 != NULL) || (cur->c2 != NULL)) { |
| 928 | cur = (cur->c1 != NULL) ? cur->c1 : cur->c2; |
| 929 | depth += 1; |
| 930 | } |
| 931 | |
| 932 | switch (cur->type) { |
| 933 | case XML_ELEMENT_CONTENT_PCDATA: |
| 934 | case XML_ELEMENT_CONTENT_ELEMENT: |
| 935 | case XML_ELEMENT_CONTENT_SEQ: |
| 936 | case XML_ELEMENT_CONTENT_OR: |
| 937 | break; |
| 938 | default: |
| 939 | xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, |
| 940 | "Internal: ELEMENT content corrupted invalid type\n", |
| 941 | NULL); |
| 942 | return; |
| 943 | } |
| 944 | if (dict) { |
| 945 | if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) |
| 946 | xmlFree((xmlChar *) cur->name); |
| 947 | if ((cur->prefix != NULL) && (!xmlDictOwns(dict, cur->prefix))) |
| 948 | xmlFree((xmlChar *) cur->prefix); |
| 949 | } else { |
| 950 | if (cur->name != NULL) xmlFree((xmlChar *) cur->name); |
| 951 | if (cur->prefix != NULL) xmlFree((xmlChar *) cur->prefix); |
| 952 | } |
| 953 | parent = cur->parent; |
| 954 | if ((depth == 0) || (parent == NULL)) { |
| 955 | xmlFree(cur); |
| 956 | break; |
| 957 | } |
| 958 | if (cur == parent->c1) |
| 959 | parent->c1 = NULL; |
| 960 | else |
| 961 | parent->c2 = NULL; |
| 962 | xmlFree(cur); |
| 963 | |
| 964 | if (parent->c2 != NULL) { |
| 965 | cur = parent->c2; |
| 966 | } else { |
| 967 | depth -= 1; |
| 968 | cur = parent; |
| 969 | } |
| 970 | } |
| 971 | } |
no test coverage detected