* xmlRelaxNGLoadExternalRef: * @ctxt: the parser context * @URL: the normalized URL * @ns: the inherited ns if any * * 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 xmlRelaxNGDocumentPtr or NULL in case of er
| 1919 | * Returns the xmlRelaxNGDocumentPtr or NULL in case of error |
| 1920 | */ |
| 1921 | static xmlRelaxNGDocumentPtr |
| 1922 | xmlRelaxNGLoadExternalRef(xmlRelaxNGParserCtxtPtr ctxt, |
| 1923 | const xmlChar * URL, const xmlChar * ns) |
| 1924 | { |
| 1925 | xmlRelaxNGDocumentPtr ret = NULL; |
| 1926 | xmlDocPtr doc; |
| 1927 | xmlNodePtr root; |
| 1928 | int i; |
| 1929 | |
| 1930 | /* |
| 1931 | * check against recursion in the stack |
| 1932 | */ |
| 1933 | for (i = 0; i < ctxt->docNr; i++) { |
| 1934 | if (xmlStrEqual(ctxt->docTab[i]->href, URL)) { |
| 1935 | xmlRngPErr(ctxt, NULL, XML_RNGP_EXTERNALREF_RECURSE, |
| 1936 | "Detected an externalRef recursion for %s\n", URL, |
| 1937 | NULL); |
| 1938 | return (NULL); |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | /* |
| 1943 | * load the document |
| 1944 | */ |
| 1945 | doc = xmlRelaxReadFile(ctxt, (const char *) URL); |
| 1946 | if (doc == NULL) { |
| 1947 | xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR, |
| 1948 | "xmlRelaxNG: could not load %s\n", URL, NULL); |
| 1949 | return (NULL); |
| 1950 | } |
| 1951 | |
| 1952 | /* |
| 1953 | * Allocate the document structures and register it first. |
| 1954 | */ |
| 1955 | ret = (xmlRelaxNGDocumentPtr) xmlMalloc(sizeof(xmlRelaxNGDocument)); |
| 1956 | if (ret == NULL) { |
| 1957 | xmlRngPErrMemory(ctxt); |
| 1958 | xmlFreeDoc(doc); |
| 1959 | return (NULL); |
| 1960 | } |
| 1961 | memset(ret, 0, sizeof(xmlRelaxNGDocument)); |
| 1962 | ret->doc = doc; |
| 1963 | ret->href = xmlStrdup(URL); |
| 1964 | ret->next = ctxt->documents; |
| 1965 | ret->externalRef = 1; |
| 1966 | ctxt->documents = ret; |
| 1967 | |
| 1968 | /* |
| 1969 | * transmit the ns if needed |
| 1970 | */ |
| 1971 | if (ns != NULL) { |
| 1972 | root = xmlDocGetRootElement(doc); |
| 1973 | if (root != NULL) { |
| 1974 | if (xmlHasProp(root, BAD_CAST "ns") == NULL) { |
| 1975 | xmlSetProp(root, BAD_CAST "ns", ns); |
| 1976 | } |
| 1977 | } |
| 1978 | } |
no test coverage detected