MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlRelaxNGLoadExternalRef

Function xmlRelaxNGLoadExternalRef

ThirdParty/libxml2/vtklibxml2/relaxng.c:1921–1997  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

1919 * Returns the xmlRelaxNGDocumentPtr or NULL in case of error
1920 */
1921static xmlRelaxNGDocumentPtr
1922xmlRelaxNGLoadExternalRef(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 }

Callers 1

xmlRelaxNGCleanupTreeFunction · 0.85

Calls 11

xmlStrEqualFunction · 0.85
xmlRelaxReadFileFunction · 0.85
xmlRngPErrMemoryFunction · 0.85
xmlFreeDocFunction · 0.85
xmlStrdupFunction · 0.85
xmlDocGetRootElementFunction · 0.85
xmlHasPropFunction · 0.85
xmlSetPropFunction · 0.85
xmlRelaxNGDocumentPushFunction · 0.85
xmlRelaxNGCleanupDocFunction · 0.85
xmlRelaxNGDocumentPopFunction · 0.85

Tested by

no test coverage detected