* xmlRelaxNGCleanupTree: * @ctxt: a Relax-NG parser context * @root: an xmlNodePtr subtree * * Cleanup the subtree from unwanted nodes for parsing, resolve * Include and externalRef lookups. */
| 6896 | * Include and externalRef lookups. |
| 6897 | */ |
| 6898 | static void |
| 6899 | xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) |
| 6900 | { |
| 6901 | xmlNodePtr cur, delete; |
| 6902 | |
| 6903 | delete = NULL; |
| 6904 | cur = root; |
| 6905 | while (cur != NULL) { |
| 6906 | if (delete != NULL) { |
| 6907 | xmlUnlinkNode(delete); |
| 6908 | xmlFreeNode(delete); |
| 6909 | delete = NULL; |
| 6910 | } |
| 6911 | if (cur->type == XML_ELEMENT_NODE) { |
| 6912 | /* |
| 6913 | * Simplification 4.1. Annotations |
| 6914 | */ |
| 6915 | if ((cur->ns == NULL) || |
| 6916 | (!xmlStrEqual(cur->ns->href, xmlRelaxNGNs))) { |
| 6917 | if ((cur->parent != NULL) && |
| 6918 | (cur->parent->type == XML_ELEMENT_NODE) && |
| 6919 | ((xmlStrEqual(cur->parent->name, BAD_CAST "name")) || |
| 6920 | (xmlStrEqual(cur->parent->name, BAD_CAST "value")) || |
| 6921 | (xmlStrEqual(cur->parent->name, BAD_CAST "param")))) { |
| 6922 | xmlRngPErr(ctxt, cur, XML_RNGP_FOREIGN_ELEMENT, |
| 6923 | "element %s doesn't allow foreign elements\n", |
| 6924 | cur->parent->name, NULL); |
| 6925 | } |
| 6926 | delete = cur; |
| 6927 | goto skip_children; |
| 6928 | } else { |
| 6929 | xmlRelaxNGCleanupAttributes(ctxt, cur); |
| 6930 | if (xmlStrEqual(cur->name, BAD_CAST "externalRef")) { |
| 6931 | xmlChar *href, *ns, *base, *URL; |
| 6932 | xmlRelaxNGDocumentPtr docu; |
| 6933 | xmlNodePtr tmp; |
| 6934 | xmlURIPtr uri; |
| 6935 | |
| 6936 | ns = xmlGetProp(cur, BAD_CAST "ns"); |
| 6937 | if (ns == NULL) { |
| 6938 | tmp = cur->parent; |
| 6939 | while ((tmp != NULL) && |
| 6940 | (tmp->type == XML_ELEMENT_NODE)) { |
| 6941 | ns = xmlGetProp(tmp, BAD_CAST "ns"); |
| 6942 | if (ns != NULL) |
| 6943 | break; |
| 6944 | tmp = tmp->parent; |
| 6945 | } |
| 6946 | } |
| 6947 | href = xmlGetProp(cur, BAD_CAST "href"); |
| 6948 | if (href == NULL) { |
| 6949 | xmlRngPErr(ctxt, cur, XML_RNGP_MISSING_HREF, |
| 6950 | "xmlRelaxNGParse: externalRef has no href attribute\n", |
| 6951 | NULL, NULL); |
| 6952 | if (ns != NULL) |
| 6953 | xmlFree(ns); |
| 6954 | delete = cur; |
| 6955 | goto skip_children; |
no test coverage detected