bool netCDFWriterConfiguration::Parse(const char *pszFilename) { CPLXMLNode *psRoot = STARTS_WITH(pszFilename, "<Configuration") ? CPLParseXMLString(pszFilename) : CPLParseXMLFile(pszFilename); if( psRoot == NULL ) return false; CPLXMLTreeCloser oCloser(psRoot); for( CPLXMLNode *psIter = psRoot->psChild; psIter != NULL; psIter = psIter->psNext ) { if( psIter->eType != CXT_Element ) continue; if( EQUAL(psIter->pszValue, "DatasetCreationOption") ) { SetNameValue(psIter, m_oDatasetCreationOptions); } else if( EQUAL(psIter->pszValue, "LayerCreationOption") ) { SetNameValue(psIter, m_oLayerCreationOptions); } else if( EQUAL(psIter->pszValue, "Attribute") ) { netCDFWriterConfigAttribute oAtt; if( oAtt.Parse(psIter) ) m_aoAttributes.push_back(oAtt); } else if( EQUAL(psIter->pszValue, "Field") ) { netCDFWriterConfigField oField; if( oField.Parse(psIter) ) m_oFields[!oField.m_osName.empty() ? oField.m_osName : CPLString("__") + oField.m_osNetCDFName] = oField; } else if( EQUAL(psIter->pszValue, "Layer") ) { netCDFWriterConfigLayer oLayer; if( oLayer.Parse(psIter) ) m_oLayers[oLayer.m_osName] = oLayer; } else { CPLDebug("GDAL_netCDF", "Ignoring %s", psIter->pszValue); } } m_bIsValid = true; return true; }
bool GMLASConfiguration::Load(const char* pszFilename) { // Allow configuration to be inlined CPLXMLNode* psRoot = STARTS_WITH(pszFilename, "<Configuration>") ? CPLParseXMLString(pszFilename) : CPLParseXMLFile(pszFilename); if( psRoot == NULL ) { Finalize(); return false; } CPLXMLTreeCloser oCloser(psRoot); // Validate the configuration file if( CPLTestBool(CPLGetConfigOption("GDAL_XML_VALIDATION", "YES")) ) { const char* pszXSD = CPLFindFile( "gdal", "gmlasconf.xsd" ); if( pszXSD != NULL ) { std::vector<CPLString> aosErrors; const CPLErr eErrClass = CPLGetLastErrorType(); const CPLErrorNum nErrNum = CPLGetLastErrorNo(); const CPLString osErrMsg = CPLGetLastErrorMsg(); CPLPushErrorHandlerEx(GMLASConfigurationErrorHandler, &aosErrors); int bRet = CPLValidateXML(pszFilename, pszXSD, NULL); CPLPopErrorHandler(); if( !bRet && aosErrors.size() > 0 && strstr(aosErrors[0].c_str(), "missing libxml2 support") == NULL ) { for(size_t i = 0; i < aosErrors.size(); i++) { CPLError(CE_Warning, CPLE_AppDefined, "%s", aosErrors[i].c_str()); } } else { CPLErrorSetState(eErrClass, nErrNum, osErrMsg); } } } m_bAllowRemoteSchemaDownload = CPLGetXMLBoolValue(psRoot, "=Configuration.AllowRemoteSchemaDownload", ALLOW_REMOTE_SCHEMA_DOWNLOAD_DEFAULT ); m_bAllowXSDCache = CPLGetXMLBoolValue( psRoot, "=Configuration.SchemaCache.enabled", ALLOW_XSD_CACHE_DEFAULT ); if( m_bAllowXSDCache ) { m_osXSDCacheDirectory = CPLGetXMLValue(psRoot, "=Configuration.SchemaCache.Directory", ""); } m_bValidate = CPLGetXMLBoolValue( psRoot, "=Configuration.Validation.enabled", VALIDATE_DEFAULT ); if( m_bValidate ) { m_bFailIfValidationError = CPLGetXMLBoolValue(psRoot, "=Configuration.Validation.FailIfError", FAIL_IF_VALIDATION_ERROR_DEFAULT ); } m_bExposeMetadataLayers = CPLGetXMLBoolValue( psRoot, "=Configuration.ExposeMetadataLayers", EXPOSE_METADATA_LAYERS_DEFAULT ); m_bAlwaysGenerateOGRId = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.AlwaysGenerateOGRId", ALWAYS_GENERATE_OGR_ID_DEFAULT ); m_bRemoveUnusedLayers = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.RemoveUnusedLayers", REMOVE_UNUSED_LAYERS_DEFAULT ); m_bRemoveUnusedFields = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.RemoveUnusedFields", REMOVE_UNUSED_FIELDS_DEFAULT ); m_bUseArrays = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.UseArrays", USE_ARRAYS_DEFAULT ); m_bIncludeGeometryXML = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.GML.IncludeGeometryXML", INCLUDE_GEOMETRY_XML_DEFAULT ); m_bInstantiateGMLFeaturesOnly = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.GML.InstantiateGMLFeaturesOnly", INSTANTIATE_GML_FEATURES_ONLY_DEFAULT ); m_nIdentifierMaxLength = atoi( CPLGetXMLValue( psRoot, "=Configuration.LayerBuildingRules.IdentifierMaxLength", "0" ) ); m_bCaseInsensitiveIdentifier = CPLGetXMLBoolValue( psRoot, "=Configuration.LayerBuildingRules.CaseInsensitiveIdentifier", CASE_INSENSITIVE_IDENTIFIER_DEFAULT ); CPLXMLNode* psIgnoredXPaths = CPLGetXMLNode(psRoot, "=Configuration.IgnoredXPaths"); if( psIgnoredXPaths ) { const bool bGlobalWarnIfIgnoredXPathFound = CPLGetXMLBoolValue( psIgnoredXPaths, "WarnIfIgnoredXPathFoundInDocInstance", WARN_IF_EXCLUDED_XPATH_FOUND_DEFAULT ); CPLXMLNode* psNamespaces = CPLGetXMLNode(psIgnoredXPaths, "Namespaces"); if( psNamespaces != NULL ) { for( CPLXMLNode* psIter = psNamespaces->psChild; psIter != NULL; psIter = psIter->psNext ) { if( psIter->eType == CXT_Element && EQUAL(psIter->pszValue, "Namespace") ) { CPLString osPrefix = CPLGetXMLValue(psIter, "prefix", ""); CPLString osURI = CPLGetXMLValue(psIter, "uri", ""); if( !osPrefix.empty() && !osURI.empty() ) { if( m_oMapPrefixToURIIgnoredXPaths.find(osPrefix) == m_oMapPrefixToURIIgnoredXPaths.end() ) { m_oMapPrefixToURIIgnoredXPaths[osPrefix] = osURI; } else { CPLError(CE_Warning, CPLE_AppDefined, "Prefix %s was already mapped to %s. " "Attempt to map it to %s ignored", osPrefix.c_str(), m_oMapPrefixToURIIgnoredXPaths[osPrefix]. c_str(), osURI.c_str()); } } } } } for( CPLXMLNode* psIter = psIgnoredXPaths->psChild; psIter != NULL; psIter = psIter->psNext ) { if( psIter->eType == CXT_Element && EQUAL(psIter->pszValue, "XPath") ) { const CPLString& osXPath( CPLGetXMLValue(psIter, "", "") ); if( IsValidXPath(osXPath) ) { m_aosIgnoredXPaths.push_back( osXPath ); const bool bWarnIfIgnoredXPathFound = CPLGetXMLBoolValue( psIter, "warnIfIgnoredXPathFoundInDocInstance", bGlobalWarnIfIgnoredXPathFound ); m_oMapIgnoredXPathToWarn[ osXPath ] = bWarnIfIgnoredXPathFound; } else { CPLError(CE_Warning, CPLE_AppDefined, "XPath syntax %s not supported", osXPath.c_str()); } } } } CPLXMLNode* psXLinkResolutionNode = CPLGetXMLNode( psRoot, "=Configuration.XLinkResolution"); if( psXLinkResolutionNode != NULL ) m_oXLinkResolution.LoadFromXML( psXLinkResolutionNode ); Finalize(); return true; }