* xmlRelaxNGLoadInclude: * @ctxt: the parser context * @URL: the normalized URL * @node: the include node. * @ns: the namespace passed from the context. * * First lookup if the document is already loaded into the parser context, * check against recursion. If not found the resource is loaded and * the content is preprocessed before being returned back to the caller. * * Returns the xmlR
| 1589 | * Returns the xmlRelaxNGIncludePtr or NULL in case of error |
| 1590 | */ |
| 1591 | static xmlRelaxNGIncludePtr |
| 1592 | xmlRelaxNGLoadInclude(xmlRelaxNGParserCtxtPtr ctxt, const xmlChar * URL, |
| 1593 | xmlNodePtr node, const xmlChar * ns) |
| 1594 | { |
| 1595 | xmlRelaxNGIncludePtr ret = NULL; |
| 1596 | xmlDocPtr doc; |
| 1597 | int i; |
| 1598 | xmlNodePtr root, cur; |
| 1599 | |
| 1600 | /* |
| 1601 | * check against recursion in the stack |
| 1602 | */ |
| 1603 | for (i = 0; i < ctxt->incNr; i++) { |
| 1604 | if (xmlStrEqual(ctxt->incTab[i]->href, URL)) { |
| 1605 | xmlRngPErr(ctxt, NULL, XML_RNGP_INCLUDE_RECURSE, |
| 1606 | "Detected an Include recursion for %s\n", URL, |
| 1607 | NULL); |
| 1608 | return (NULL); |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | /* |
| 1613 | * load the document |
| 1614 | */ |
| 1615 | doc = xmlRelaxReadFile(ctxt, (const char *) URL); |
| 1616 | if (doc == NULL) { |
| 1617 | xmlRngPErr(ctxt, node, XML_RNGP_PARSE_ERROR, |
| 1618 | "xmlRelaxNG: could not load %s\n", URL, NULL); |
| 1619 | return (NULL); |
| 1620 | } |
| 1621 | |
| 1622 | /* |
| 1623 | * Allocate the document structures and register it first. |
| 1624 | */ |
| 1625 | ret = (xmlRelaxNGIncludePtr) xmlMalloc(sizeof(xmlRelaxNGInclude)); |
| 1626 | if (ret == NULL) { |
| 1627 | xmlRngPErrMemory(ctxt); |
| 1628 | xmlFreeDoc(doc); |
| 1629 | return (NULL); |
| 1630 | } |
| 1631 | memset(ret, 0, sizeof(xmlRelaxNGInclude)); |
| 1632 | ret->doc = doc; |
| 1633 | ret->href = xmlStrdup(URL); |
| 1634 | ret->next = ctxt->includes; |
| 1635 | ctxt->includes = ret; |
| 1636 | |
| 1637 | /* |
| 1638 | * transmit the ns if needed |
| 1639 | */ |
| 1640 | if (ns != NULL) { |
| 1641 | root = xmlDocGetRootElement(doc); |
| 1642 | if (root != NULL) { |
| 1643 | if (xmlHasProp(root, BAD_CAST "ns") == NULL) { |
| 1644 | xmlSetProp(root, BAD_CAST "ns", ns); |
| 1645 | } |
| 1646 | } |
| 1647 | } |
| 1648 |
no test coverage detected