MCPcopy Create free account
hub / github.com/OSGeo/gdal / CPLLoadSchemaStrInternal

Function CPLLoadSchemaStrInternal

port/cpl_xml_validate.cpp:374–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372/************************************************************************/
373
374static CPLXMLNode *CPLLoadSchemaStrInternal(CPLHashSet *hSetSchemas,
375 const char *pszFile)
376{
377 if (CPLHashSetLookup(hSetSchemas, pszFile))
378 return nullptr;
379
380 CPLHashSetInsert(hSetSchemas, CPLStrdup(pszFile));
381
382 CPLDebug("CPL", "Parsing %s", pszFile);
383
384 CPLXMLNode *psXML = CPLParseXMLFile(pszFile);
385 if (psXML == nullptr)
386 {
387 CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s", pszFile);
388 return nullptr;
389 }
390
391 CPLXMLNode *psSchema = CPLGetXMLNode(psXML, "=schema");
392 if (psSchema == nullptr)
393 {
394 psSchema = CPLGetXMLNode(psXML, "=xs:schema");
395 }
396 if (psSchema == nullptr)
397 {
398 psSchema = CPLGetXMLNode(psXML, "=xsd:schema");
399 }
400 if (psSchema == nullptr)
401 {
402 CPLError(CE_Failure, CPLE_AppDefined, "Cannot find schema node in %s",
403 pszFile);
404 CPLDestroyXMLNode(psXML);
405 return nullptr;
406 }
407
408 CPLXMLNode *psPrev = nullptr;
409 CPLXMLNode *psIter = psSchema->psChild;
410 while (psIter)
411 {
412 bool bDestroyCurrentNode = false;
413
414#ifdef HAS_VALIDATION_BUG
415 if (CPLHasLibXMLBug())
416 bDestroyCurrentNode = CPLWorkaroundLibXMLBug(psIter);
417#endif
418
419 // Load the referenced schemas, and integrate them in the main schema.
420 if (psIter->eType == CXT_Element &&
421 (strcmp(psIter->pszValue, "include") == 0 ||
422 strcmp(psIter->pszValue, "xs:include") == 0 ||
423 strcmp(psIter->pszValue, "xsd:include") == 0) &&
424 psIter->psChild != nullptr &&
425 psIter->psChild->eType == CXT_Attribute &&
426 strcmp(psIter->psChild->pszValue, "schemaLocation") == 0)
427 {
428 const char *pszIncludeSchema = psIter->psChild->psChild->pszValue;
429 char *pszFullFilename =
430 CPLStrdup(CPLFormFilenameSafe(CPLGetPathSafe(pszFile).c_str(),
431 pszIncludeSchema, nullptr)

Callers 1

CPLLoadSchemaStrFunction · 0.85

Calls 15

CPLHashSetLookupFunction · 0.85
CPLHashSetInsertFunction · 0.85
CPLStrdupFunction · 0.85
CPLDebugFunction · 0.85
CPLParseXMLFileFunction · 0.85
CPLErrorFunction · 0.85
CPLDestroyXMLNodeFunction · 0.85
CPLHasLibXMLBugFunction · 0.85
CPLWorkaroundLibXMLBugFunction · 0.85
CPLFormFilenameSafeFunction · 0.85
CPLGetPathSafeFunction · 0.85
CPLFixPathFunction · 0.85

Tested by

no test coverage detected