* xmlXIncludeParseFile: * @ctxt: the XInclude context * @URL: the URL or file path * * parse a document for XInclude */
| 303 | * parse a document for XInclude |
| 304 | */ |
| 305 | static xmlDocPtr |
| 306 | xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) { |
| 307 | xmlDocPtr ret = NULL; |
| 308 | xmlParserCtxtPtr pctxt; |
| 309 | xmlParserInputPtr inputStream; |
| 310 | |
| 311 | xmlInitParser(); |
| 312 | |
| 313 | pctxt = xmlNewParserCtxt(); |
| 314 | if (pctxt == NULL) { |
| 315 | xmlXIncludeErrMemory(ctxt); |
| 316 | return(NULL); |
| 317 | } |
| 318 | if (ctxt->errorHandler != NULL) |
| 319 | xmlCtxtSetErrorHandler(pctxt, ctxt->errorHandler, ctxt->errorCtxt); |
| 320 | |
| 321 | /* |
| 322 | * pass in the application data to the parser context. |
| 323 | */ |
| 324 | pctxt->_private = ctxt->_private; |
| 325 | |
| 326 | /* |
| 327 | * try to ensure that new documents included are actually |
| 328 | * built with the same dictionary as the including document. |
| 329 | */ |
| 330 | if ((ctxt->doc != NULL) && (ctxt->doc->dict != NULL)) { |
| 331 | if (pctxt->dict != NULL) |
| 332 | xmlDictFree(pctxt->dict); |
| 333 | pctxt->dict = ctxt->doc->dict; |
| 334 | xmlDictReference(pctxt->dict); |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * We set DTDLOAD to make sure that ID attributes declared in |
| 339 | * external DTDs are detected. |
| 340 | */ |
| 341 | xmlCtxtUseOptions(pctxt, ctxt->parseFlags | XML_PARSE_DTDLOAD); |
| 342 | |
| 343 | inputStream = xmlLoadExternalEntity(URL, NULL, pctxt); |
| 344 | if (inputStream == NULL) |
| 345 | goto error; |
| 346 | |
| 347 | inputPush(pctxt, inputStream); |
| 348 | |
| 349 | xmlParseDocument(pctxt); |
| 350 | |
| 351 | if (pctxt->wellFormed) { |
| 352 | ret = pctxt->myDoc; |
| 353 | } |
| 354 | else { |
| 355 | ret = NULL; |
| 356 | if (pctxt->myDoc != NULL) |
| 357 | xmlFreeDoc(pctxt->myDoc); |
| 358 | pctxt->myDoc = NULL; |
| 359 | } |
| 360 | |
| 361 | error: |
| 362 | if (pctxt->errNo == XML_ERR_NO_MEMORY) |
no test coverage detected