| 372 | /************************************************************************/ |
| 373 | |
| 374 | static 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) |
no test coverage detected