* xmlSchematronLoadInclude: * @ctxt: a schema validation context * @cur: the include element * * Load the include document, Push the current pointer * * Returns the updated node pointer */
| 1182 | * Returns the updated node pointer |
| 1183 | */ |
| 1184 | static xmlNodePtr |
| 1185 | xmlSchematronLoadInclude(xmlSchematronParserCtxtPtr ctxt, xmlNodePtr cur) |
| 1186 | { |
| 1187 | xmlNodePtr ret = NULL; |
| 1188 | xmlDocPtr doc = NULL; |
| 1189 | xmlChar *href = NULL; |
| 1190 | xmlChar *base = NULL; |
| 1191 | xmlChar *URI = NULL; |
| 1192 | |
| 1193 | if ((ctxt == NULL) || (cur == NULL)) |
| 1194 | return(NULL); |
| 1195 | |
| 1196 | href = xmlGetNoNsProp(cur, BAD_CAST "href"); |
| 1197 | if (href == NULL) { |
| 1198 | xmlSchematronPErr(ctxt, cur, |
| 1199 | XML_SCHEMAP_NOROOT, |
| 1200 | "Include has no href attribute", NULL, NULL); |
| 1201 | return(cur->next); |
| 1202 | } |
| 1203 | |
| 1204 | /* do the URI base composition, load and find the root */ |
| 1205 | base = xmlNodeGetBase(cur->doc, cur); |
| 1206 | URI = xmlBuildURI(href, base); |
| 1207 | doc = xmlReadFile((const char *) URI, NULL, SCHEMATRON_PARSE_OPTIONS); |
| 1208 | if (doc == NULL) { |
| 1209 | xmlSchematronPErr(ctxt, cur, |
| 1210 | XML_SCHEMAP_FAILED_LOAD, |
| 1211 | "could not load include '%s'.\n", |
| 1212 | URI, NULL); |
| 1213 | goto done; |
| 1214 | } |
| 1215 | ret = xmlDocGetRootElement(doc); |
| 1216 | if (ret == NULL) { |
| 1217 | xmlSchematronPErr(ctxt, cur, |
| 1218 | XML_SCHEMAP_FAILED_LOAD, |
| 1219 | "could not find root from include '%s'.\n", |
| 1220 | URI, NULL); |
| 1221 | goto done; |
| 1222 | } |
| 1223 | |
| 1224 | /* Success, push the include for rollback on exit */ |
| 1225 | xmlSchematronPushInclude(ctxt, doc, cur); |
| 1226 | |
| 1227 | done: |
| 1228 | if (ret == NULL) { |
| 1229 | if (doc != NULL) |
| 1230 | xmlFreeDoc(doc); |
| 1231 | } |
| 1232 | xmlFree(href); |
| 1233 | if (base != NULL) |
| 1234 | xmlFree(base); |
| 1235 | if (URI != NULL) |
| 1236 | xmlFree(URI); |
| 1237 | return(ret); |
| 1238 | } |
| 1239 | #endif |
| 1240 | |
| 1241 | /** |
nothing calls this directly
no test coverage detected