GMLFeature::~GMLFeature() { CPLFree( m_pszFID ); int i; for( i = 0; i < m_nPropertyCount; i++ ) { int nSubProperties = m_pasProperties[i].nSubProperties; if (nSubProperties == 1) CPLFree( m_pasProperties[i].aszSubProperties[0] ); else if (nSubProperties > 1) { for( int j = 0; j < nSubProperties; j++) CPLFree( m_pasProperties[i].papszSubProperties[j] ); CPLFree( m_pasProperties[i].papszSubProperties ); } } if (m_nGeometryCount == 1) { CPLDestroyXMLNode(m_apsGeometry[0]); } else if (m_nGeometryCount > 1) { for(i=0;i<m_nGeometryCount;i++) CPLDestroyXMLNode(m_papsGeometry[i]); CPLFree(m_papsGeometry); } CPLFree( m_pasProperties ); CSLDestroy( m_papszOBProperties ); }
static CPLXMLNode* CPLExtractSubSchema(CPLXMLNode* psSubXML, CPLXMLNode* psMainSchema) { if (psSubXML->eType == CXT_Element && strcmp(psSubXML->pszValue, "?xml") == 0) { CPLXMLNode* psNext = psSubXML->psNext; psSubXML->psNext = NULL; CPLDestroyXMLNode(psSubXML); psSubXML = psNext; } if (psSubXML != NULL && psSubXML->eType == CXT_Comment) { CPLXMLNode* psNext = psSubXML->psNext; psSubXML->psNext = NULL; CPLDestroyXMLNode(psSubXML); psSubXML = psNext; } if (psSubXML != NULL && psSubXML->eType == CXT_Element && (strcmp(psSubXML->pszValue, "schema") == 0 || strcmp(psSubXML->pszValue, "xs:schema") == 0 || strcmp(psSubXML->pszValue, "xsd:schema") == 0) && psSubXML->psNext == NULL) { CPLXMLNode* psNext = psSubXML->psChild; while(psNext != NULL && psNext->eType != CXT_Element && psNext->psNext != NULL && psNext->psNext->eType != CXT_Element) { /* Add xmlns: from subschema to main schema if missing */ if (psNext->eType == CXT_Attribute && STARTS_WITH(psNext->pszValue, "xmlns:") && CPLGetXMLValue(psMainSchema, psNext->pszValue, NULL) == NULL) { CPLXMLNode* psAttr = CPLCreateXMLNode(NULL, CXT_Attribute, psNext->pszValue); CPLCreateXMLNode(psAttr, CXT_Text, psNext->psChild->pszValue); psAttr->psNext = psMainSchema->psChild; psMainSchema->psChild = psAttr; } psNext = psNext->psNext; } if (psNext != NULL && psNext->eType != CXT_Element && psNext->psNext != NULL && psNext->psNext->eType == CXT_Element) { CPLXMLNode* psNext2 = psNext->psNext; psNext->psNext = NULL; CPLDestroyXMLNode(psSubXML); psSubXML = psNext2; } } return psSubXML; }
DIMAPDataset::~DIMAPDataset() { FlushCache(); CPLDestroyXMLNode( psProduct ); CPLFree( pszGCPProjection ); if( nGCPCount > 0 ) { GDALDeinitGCPs( nGCPCount, pasGCPList ); CPLFree( pasGCPList ); } if( poImageDS != NULL ) delete poImageDS; CSLDestroy(papszXMLDimapMetadata); /* -------------------------------------------------------------------- */ /* Disconnect the bands so our destructor doesn't try and */ /* delete them since they really belonged to poImageDS. */ /* -------------------------------------------------------------------- */ int iBand; for( iBand = 0; iBand < GetRasterCount(); iBand++ ) papoBands[iBand] = NULL; }
void GDALPamRasterBand::PamClear() { if( psPam ) { if( psPam->poColorTable ) delete psPam->poColorTable; psPam->poColorTable = NULL; CPLFree( psPam->pszUnitType ); CSLDestroy( psPam->papszCategoryNames ); if( psPam->poDefaultRAT != NULL ) { delete psPam->poDefaultRAT; psPam->poDefaultRAT = NULL; } if (psPam->psSavedHistograms != NULL) { CPLDestroyXMLNode (psPam->psSavedHistograms ); psPam->psSavedHistograms = NULL; } CPLFree( psPam ); psPam = NULL; } }
/** * LoadMetadata() */ void GDALMDReaderResursDK1::LoadMetadata() { if(m_bIsMetadataLoad) return; if (!m_osXMLSourceFilename.empty()) { CPLXMLNode* psNode = CPLParseXMLFile(m_osXMLSourceFilename); if(psNode != NULL) { CPLXMLNode* pMSPRootNode = CPLSearchXMLNode(psNode, "=MSP_ROOT"); if(pMSPRootNode != NULL) { m_papszIMDMD = ReadXMLToList(pMSPRootNode, m_papszIMDMD, "MSP_ROOT"); } CPLDestroyXMLNode(psNode); } } m_papszDEFAULTMD = CSLAddNameValue(m_papszDEFAULTMD, MD_NAME_MDTYPE, "MSP"); m_bIsMetadataLoad = true; if(NULL == m_papszIMDMD) { return; } //extract imagery metadata const char* pszSatId = CSLFetchNameValue(m_papszIMDMD, "MSP_ROOT.cCodeKA"); if(NULL != pszSatId) { m_papszIMAGERYMD = CSLAddNameValue(m_papszIMAGERYMD, MD_NAME_SATELLITE, CPLStripQuotes(pszSatId)); } const char* pszDate = CSLFetchNameValue(m_papszIMDMD, "MSP_ROOT.Normal.dSceneDate"); if(NULL != pszDate) { const char* pszTime = CSLFetchNameValue(m_papszIMDMD, "MSP_ROOT.Normal.tSceneTime"); if(NULL == pszTime) pszTime = "00:00:00.000000"; char buffer[80]; time_t timeMid = GetAcquisitionTimeFromString(CPLSPrintf( "%s %s", pszDate, pszTime)); strftime (buffer, 80, MD_DATETIMEFORMAT, localtime(&timeMid)); m_papszIMAGERYMD = CSLAddNameValue(m_papszIMAGERYMD, MD_NAME_ACQDATETIME, buffer); } m_papszIMAGERYMD = CSLAddNameValue(m_papszIMAGERYMD, MD_NAME_CLOUDCOVER, MD_CLOUDCOVER_NA); }
OGRGeometryH OGR_G_CreateFromGML( const char *pszGML ) { if( pszGML == NULL || strlen(pszGML) == 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "GML Geometry is empty in GML2OGRGeometry()." ); return NULL; } /* -------------------------------------------------------------------- */ /* Try to parse the XML snippet using the MiniXML API. If this */ /* fails, we assume the minixml api has already posted a CPL */ /* error, and just return NULL. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psGML = CPLParseXMLString( pszGML ); if( psGML == NULL ) return NULL; /* -------------------------------------------------------------------- */ /* Convert geometry recursively. */ /* -------------------------------------------------------------------- */ OGRGeometry *poGeometry; poGeometry = GML2OGRGeometry_XMLNode( psGML ); CPLDestroyXMLNode( psGML ); return (OGRGeometryH) poGeometry; }
void GMLFeature::SetGeometryDirectly( int nIdx, CPLXMLNode* psGeom ) { if( nIdx == 0 && m_nGeometryCount <= 1 ) { SetGeometryDirectly( psGeom ); return; } else if( nIdx > 0 && m_nGeometryCount <= 1 ) { m_papsGeometry = (CPLXMLNode **) CPLMalloc(2 * sizeof(CPLXMLNode *)); m_papsGeometry[0] = m_apsGeometry[0]; m_papsGeometry[1] = NULL; m_apsGeometry[0] = NULL; } if( nIdx >= m_nGeometryCount ) { m_papsGeometry = (CPLXMLNode **) CPLRealloc(m_papsGeometry, (nIdx + 2) * sizeof(CPLXMLNode *)); for( int i = m_nGeometryCount; i <= nIdx + 1; i++ ) m_papsGeometry[i] = NULL; m_nGeometryCount = nIdx + 1; } if (m_papsGeometry[nIdx] != NULL) CPLDestroyXMLNode(m_papsGeometry[nIdx]); m_papsGeometry[nIdx] = psGeom; }
int GDALJP2Metadata::GMLSRSLookup( const char *pszURN ) { CPLXMLNode *psDictEntry = GetDictionaryItem( papszGMLMetadata, pszURN ); if( psDictEntry == NULL ) return FALSE; /* -------------------------------------------------------------------- */ /* Reserialize this fragment. */ /* -------------------------------------------------------------------- */ char *pszDictEntryXML = CPLSerializeXMLTree( psDictEntry ); CPLDestroyXMLNode( psDictEntry ); /* -------------------------------------------------------------------- */ /* Try to convert into an OGRSpatialReference. */ /* -------------------------------------------------------------------- */ OGRSpatialReference oSRS; int bSuccess = FALSE; if( oSRS.importFromXML( pszDictEntryXML ) == OGRERR_NONE ) { CPLFree( pszProjection ); pszProjection = NULL; oSRS.exportToWkt( &pszProjection ); bSuccess = TRUE; } CPLFree( pszDictEntryXML ); return bSuccess; }
int gv_symbol_manager_save_vector_symbol( GvSymbolManager *manager, const char *symbol_name, const char *new_name ) { GvSymbolObj *symbol; /* allocate a new symbol object */ symbol = g_hash_table_lookup( manager->symbol_cache, symbol_name ); CPLDebug("OpenEV", "save_vector_symbol(%s->%s)", symbol_name, new_name ); if ( symbol && symbol->type == GV_SYMBOL_VECTOR ) { GvShape *shape; CPLXMLNode *xml_shape; shape = (GvShape *)symbol->buffer; xml_shape = gv_shape_to_xml_tree( shape ); if ( CPLSerializeXMLTreeToFile( xml_shape, new_name ) ) { CPLDestroyXMLNode( xml_shape ); return TRUE; } } return FALSE; }
OGRErr OGRMILayerAttrIndex::SaveConfigToXML() { if( nIndexCount == 0 ) return OGRERR_NONE; /* -------------------------------------------------------------------- */ /* Create the XML tree corresponding to this layer. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psRoot; psRoot = CPLCreateXMLNode( NULL, CXT_Element, "OGRMILayerAttrIndex" ); CPLCreateXMLElementAndValue( psRoot, "MIIDFilename", CPLGetFilename( pszMIINDFilename ) ); for( int i = 0; i < nIndexCount; i++ ) { OGRMIAttrIndex *poAI = papoIndexList[i]; CPLXMLNode *psIndex; psIndex = CPLCreateXMLNode( psRoot, CXT_Element, "OGRMIAttrIndex" ); CPLCreateXMLElementAndValue( psIndex, "FieldIndex", CPLSPrintf( "%d", poAI->iField ) ); CPLCreateXMLElementAndValue( psIndex, "FieldName", poLayer->GetLayerDefn()->GetFieldDefn(poAI->iField)->GetNameRef() ); CPLCreateXMLElementAndValue( psIndex, "IndexIndex", CPLSPrintf( "%d", poAI->iIndex ) ); } /* -------------------------------------------------------------------- */ /* Save it. */ /* -------------------------------------------------------------------- */ char *pszRawXML = CPLSerializeXMLTree( psRoot ); FILE *fp; CPLDestroyXMLNode( psRoot ); fp = VSIFOpen( pszMetadataFilename, "wb" ); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to pen `%s' for write.", pszMetadataFilename ); CPLFree( pszRawXML ); return OGRERR_FAILURE; } VSIFWrite( pszRawXML, 1, strlen(pszRawXML), fp ); VSIFClose( fp ); CPLFree( pszRawXML ); return OGRERR_NONE; }
static OGRGeometry* ParseKMLGeometry(const char* pszKML) { CPLXMLNode* psXML = CPLParseXMLString(pszKML); if (psXML == nullptr) return nullptr; if (psXML->eType != CXT_Element) { CPLDestroyXMLNode(psXML); return nullptr; } OGRGeometry* poGeom = ParseKMLGeometry(psXML); CPLDestroyXMLNode(psXML); return poGeom; }
void GMLFeature::SetGeometryDirectly( CPLXMLNode* psGeom ) { if (m_apsGeometry[0] != NULL) CPLDestroyXMLNode(m_apsGeometry[0]); m_nGeometryCount = 1; m_apsGeometry[0] = psGeom; }
int OGRFMECacheIndex::Load() { /* -------------------------------------------------------------------- */ /* Lock the cache index file if not already locked. */ /* -------------------------------------------------------------------- */ if( hLock == NULL && !Lock() ) return FALSE; if( psTree != NULL ) { CPLDestroyXMLNode( psTree ); psTree = NULL; } /* -------------------------------------------------------------------- */ /* Open the index file. If we don't get it, we assume it is */ /* because it doesn't exist, and we create a "stub" tree in */ /* memory. */ /* -------------------------------------------------------------------- */ FILE *fpIndex; int nLength; char *pszIndexBuffer; fpIndex = VSIFOpen( GetPath(), "rb" ); if( fpIndex == NULL ) { psTree = CPLCreateXMLNode( NULL, CXT_Element, "OGRFMECacheIndex" ); return TRUE; } /* -------------------------------------------------------------------- */ /* Load the data from the file. */ /* -------------------------------------------------------------------- */ VSIFSeek( fpIndex, 0, SEEK_END ); nLength = VSIFTell( fpIndex ); VSIFSeek( fpIndex, 0, SEEK_SET ); pszIndexBuffer = (char *) CPLMalloc(nLength+1); if( (int) VSIFRead( pszIndexBuffer, 1, nLength, fpIndex ) != nLength ) { CPLError( CE_Failure, CPLE_FileIO, "Read of %d byte index file failed.", nLength ); return FALSE; } VSIFClose( fpIndex ); /* -------------------------------------------------------------------- */ /* Parse the result into an inmemory XML tree. */ /* -------------------------------------------------------------------- */ pszIndexBuffer[nLength] = '\0'; psTree = CPLParseXMLString( pszIndexBuffer ); CPLFree( pszIndexBuffer ); return psTree != NULL; }
/** * LoadMetadata() */ void GDALMDReaderRapidEye::LoadMetadata() { if(m_bIsMetadataLoad) return; CPLXMLNode* psNode = CPLParseXMLFile(m_osXMLSourceFilename); if(psNode != NULL) { CPLXMLNode* pRootNode = CPLSearchXMLNode(psNode, "=re:EarthObservation"); if(pRootNode != NULL) { m_papszIMDMD = ReadXMLToList(pRootNode->psChild, m_papszIMDMD); } CPLDestroyXMLNode(psNode); } m_papszDEFAULTMD = CSLAddNameValue(m_papszDEFAULTMD, MD_NAME_MDTYPE, "RE"); m_bIsMetadataLoad = true; if(NULL == m_papszIMDMD) { return; } //extract imagery metadata const char* pszSatId = CSLFetchNameValue(m_papszIMDMD, "gml:using.eop:EarthObservationEquipment.eop:platform.eop:Platform.eop:serialIdentifier"); if(NULL != pszSatId) { m_papszIMAGERYMD = CSLAddNameValue(m_papszIMAGERYMD, MD_NAME_SATELLITE, CPLStripQuotes(pszSatId)); } const char* pszDateTime = CSLFetchNameValue(m_papszIMDMD, "gml:using.eop:EarthObservationEquipment.eop:acquisitionParameters.re:Acquisition.re:acquisitionDateTime"); if(NULL != pszDateTime) { char buffer[80]; time_t timeMid = GetAcquisitionTimeFromString(pszDateTime); strftime (buffer, 80, MD_DATETIMEFORMAT, localtime(&timeMid)); m_papszIMAGERYMD = CSLAddNameValue(m_papszIMAGERYMD, MD_NAME_ACQDATETIME, buffer); } const char* pszCC = CSLFetchNameValue(m_papszIMDMD, "gml:resultOf.re:EarthObservationResult.opt:cloudCoverPercentage"); if(NULL != pszSatId) { m_papszIMAGERYMD = CSLAddNameValue(m_papszIMAGERYMD, MD_NAME_CLOUDCOVER, pszCC); } }
OGRFMECacheIndex::~OGRFMECacheIndex() { if( psTree != NULL ) { Unlock(); CPLDestroyXMLNode( psTree ); psTree = NULL; } CPLFree( pszPath ); }
GDALDataset *ECRGTOCDataset::Open( GDALOpenInfo * poOpenInfo ) { const char *pszFilename = poOpenInfo->pszFilename; CPLString osProduct, osDiscId; if( !Identify( poOpenInfo ) ) return NULL; if( EQUALN(pszFilename, "ECRG_TOC_ENTRY:",strlen("ECRG_TOC_ENTRY:"))) { pszFilename += strlen("ECRG_TOC_ENTRY:"); osProduct = pszFilename; size_t iPos = osProduct.find(":"); if (iPos == std::string::npos) return NULL; osProduct.resize(iPos); pszFilename += iPos + 1; osDiscId = pszFilename; iPos = osDiscId.find(":"); if (iPos == std::string::npos) return NULL; osDiscId.resize(iPos); pszFilename += iPos + 1; } /* -------------------------------------------------------------------- */ /* Parse the XML file */ /* -------------------------------------------------------------------- */ CPLXMLNode* psXML = CPLParseXMLFile(pszFilename); if (psXML == NULL) { return NULL; } GDALDataset* poDS = Build( pszFilename, psXML, osProduct, osDiscId, poOpenInfo->pszFilename); CPLDestroyXMLNode(psXML); if (poDS && poOpenInfo->eAccess == GA_Update) { CPLError(CE_Failure, CPLE_NotSupported, "ECRGTOC driver does not support update mode"); delete poDS; return NULL; } return poDS; }
OGRVRTDataSource::~OGRVRTDataSource() { CPLFree(pszName); OGRVRTDataSource::CloseDependentDatasets(); CPLFree(paeLayerType); if( psTree != nullptr) CPLDestroyXMLNode(psTree); delete poLayerPool; }
CPLErr GDALPamRasterBand::SetDefaultHistogram( double dfMin, double dfMax, int nBuckets, int *panHistogram) { CPLXMLNode *psNode; PamInitialize(); if( psPam == NULL ) return GDALRasterBand::SetDefaultHistogram( dfMin, dfMax, nBuckets, panHistogram ); /* -------------------------------------------------------------------- */ /* Do we have a matching histogram we should replace? */ /* -------------------------------------------------------------------- */ psNode = PamFindMatchingHistogram( psPam->psSavedHistograms, dfMin, dfMax, nBuckets, TRUE, TRUE ); if( psNode != NULL ) { /* blow this one away */ CPLRemoveXMLChild( psPam->psSavedHistograms, psNode ); CPLDestroyXMLNode( psNode ); } /* -------------------------------------------------------------------- */ /* Translate into a histogram XML tree. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psHistItem; psHistItem = PamHistogramToXMLTree( dfMin, dfMax, nBuckets, panHistogram, TRUE, FALSE ); if( psHistItem == NULL ) return CE_Failure; /* -------------------------------------------------------------------- */ /* Insert our new default histogram at the front of the */ /* histogram list so that it will be the default histogram. */ /* -------------------------------------------------------------------- */ psPam->poParentDS->MarkPamDirty(); if( psPam->psSavedHistograms == NULL ) psPam->psSavedHistograms = CPLCreateXMLNode( NULL, CXT_Element, "Histograms" ); psHistItem->psNext = psPam->psSavedHistograms->psChild; psPam->psSavedHistograms->psChild = psHistItem; return CE_None; }
VRTRasterBand::~VRTRasterBand() { CPLFree( pszUnitType ); if( poColorTable != NULL ) delete poColorTable; CSLDestroy( papszCategoryNames ); if( psSavedHistograms != NULL ) CPLDestroyXMLNode( psSavedHistograms ); delete poMaskBand; }
void VRTDataset::FlushCache() { GDALDataset::FlushCache(); if( !bNeedsFlush || bWritable == FALSE) return; bNeedsFlush = FALSE; // We don't write to disk if there is no filename. This is a // memory only dataset. if( strlen(GetDescription()) == 0 || EQUALN(GetDescription(),"<VRTDataset",11) ) return; /* -------------------------------------------------------------------- */ /* Create the output file. */ /* -------------------------------------------------------------------- */ VSILFILE *fpVRT; fpVRT = VSIFOpenL( GetDescription(), "w" ); if( fpVRT == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "Failed to write .vrt file in FlushCache()." ); return; } /* -------------------------------------------------------------------- */ /* Convert tree to a single block of XML text. */ /* -------------------------------------------------------------------- */ char *pszVRTPath = CPLStrdup(CPLGetPath(GetDescription())); CPLXMLNode *psDSTree = SerializeToXML( pszVRTPath ); char *pszXML; pszXML = CPLSerializeXMLTree( psDSTree ); CPLDestroyXMLNode( psDSTree ); CPLFree( pszVRTPath ); /* -------------------------------------------------------------------- */ /* Write to disk. */ /* -------------------------------------------------------------------- */ VSIFWriteL( pszXML, 1, strlen(pszXML), fpVRT ); VSIFCloseL( fpVRT ); CPLFree( pszXML ); }
GMLHandler::~GMLHandler() { if (apsXMLNode.size() >= 2 && apsXMLNode[1].psNode != NULL) CPLDestroyXMLNode(apsXMLNode[1].psNode); CPLFree( m_pszCurField ); CPLFree( m_pszGeometry ); CPLFree( m_pszCityGMLGenericAttrName ); CPLFree( m_pszHref ); CPLFree( m_pszUom ); CPLFree( m_pszValue ); CPLFree( pasGeometryNames ); }
bool GMLRegistry::Parse() { if( osRegistryPath.empty() ) { const char *pszFilename = CPLFindFile("gdal", "gml_registry.xml"); if( pszFilename ) osRegistryPath = pszFilename; } if( osRegistryPath.empty() ) return false; CPLXMLNode *psRootNode = CPLParseXMLFile(osRegistryPath); if( psRootNode == NULL ) return false; CPLXMLNode *psRegistryNode = CPLGetXMLNode(psRootNode, "=gml_registry"); if( psRegistryNode == NULL ) { CPLDestroyXMLNode(psRootNode); return false; } CPLXMLNode *psIter = psRegistryNode->psChild; while( psIter != NULL ) { if( psIter->eType == CXT_Element && strcmp(psIter->pszValue, "namespace") == 0 ) { GMLRegistryNamespace oNameSpace; if( oNameSpace.Parse(osRegistryPath, psIter) ) { aoNamespaces.push_back(oNameSpace); } } psIter = psIter->psNext; } CPLDestroyXMLNode(psRootNode); return true; }
OGRVRTDataSource::~OGRVRTDataSource() { int i; CPLFree( pszName ); for( i = 0; i < nLayers; i++ ) delete papoLayers[i]; CPLFree( papoLayers ); if( psTree != NULL) CPLDestroyXMLNode( psTree ); }
CPLErr VRTSourcedRasterBand::SetMetadata( char **papszNewMD, const char *pszDomain ) { if( pszDomain != NULL && (EQUAL(pszDomain,"new_vrt_sources") || EQUAL(pszDomain,"vrt_sources")) ) { VRTDriver *poDriver = (VRTDriver *) GDALGetDriverByName( "VRT" ); CPLErr eErr; int i; if( EQUAL(pszDomain,"vrt_sources") ) { for( int i = 0; i < nSources; i++ ) delete papoSources[i]; CPLFree( papoSources ); papoSources = NULL; nSources = 0; } for( i = 0; i < CSLCount(papszNewMD); i++ ) { const char *pszXML = CPLParseNameValue( papszNewMD[i], NULL ); CPLXMLNode *psTree = CPLParseXMLString( pszXML ); VRTSource *poSource; if( psTree == NULL ) return CE_Failure; poSource = poDriver->ParseSource( psTree, NULL ); CPLDestroyXMLNode( psTree ); if( poSource != NULL ) { eErr = AddSource( poSource ); if( eErr != CE_None ) return eErr; } else return CE_Failure; } return CE_None; } else return VRTRasterBand::SetMetadata( papszNewMD, pszDomain ); }
int main( int argc, char **argv ) { static char szXML[20000000]; FILE *fp; if( argc == 1 ) fp = stdin; else if( argv[1][0] == '-' ) { printf( "Usage: xmlreformat [filename]\n" ); exit( 0 ); } else { fp = fopen( argv[1], "rt" ); if( fp == NULL ) { printf( "Failed to open file %s.\n", argv[1] ); exit( 1 ); } } int nLen = fread( szXML, 1, sizeof(szXML), fp ); if( nLen >= (int) sizeof(szXML)-2 ) { fprintf( stderr, "xmlreformat fixed sized buffer (%d bytes) exceeded.\n", (int) sizeof(szXML) ); exit(1); } if( fp != stdin ) fclose( fp ); szXML[nLen] = '\0'; CPLXMLNode *poTree = CPLParseXMLString( szXML ); if( poTree != NULL ) { char *pszRawXML = CPLSerializeXMLTree( poTree ); printf( "%s", pszRawXML ); CPLFree( pszRawXML ); CPLDestroyXMLNode( poTree ); } return 0; }
// ************************************************************ // ParseServerException() // ************************************************************ void BaseProvider::ParseServerException(CString s) { CPLXMLNode* node = CPLParseXMLString(s); if (node) { while (node) { CPLXMLNode* nodeException = CPLGetXMLNode(node, "ServiceException"); if (nodeException) { CString msg = CPLGetXMLValue(nodeException, "", ""); CallbackHelper::ErrorMsg(Debug::Format("WMS Server exception (%s): %s", Name, msg)); } node = node->psNext; } CPLDestroyXMLNode(node); } }
MEMRasterBand::~MEMRasterBand() { if( bOwnData ) { VSIFree( pabyData ); } if( poColorTable != NULL ) delete poColorTable; CPLFree( pszUnitType ); CSLDestroy( papszCategoryNames ); if (psSavedHistograms != NULL) CPLDestroyXMLNode(psSavedHistograms); }
CPLErr GDALWMSRasterBand::ReportWMSException(const char *file_name) { CPLErr ret = CE_None; int reported_errors_count = 0; CPLXMLNode *orig_root = CPLParseXMLFile(file_name); CPLXMLNode *root = orig_root; if (root != NULL) { root = CPLGetXMLNode(root, "=ServiceExceptionReport"); } if (root != NULL) { CPLXMLNode *n = CPLGetXMLNode(root, "ServiceException"); while (n != NULL) { const char *exception = CPLGetXMLValue(n, "=ServiceException", ""); const char *exception_code = CPLGetXMLValue(n, "=ServiceException.code", ""); if (exception[0] != '\0') { if (exception_code[0] != '\0') { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: The server returned exception code '%s': %s", exception_code, exception); ++reported_errors_count; } else { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: The server returned exception: %s", exception); ++reported_errors_count; } } else if (exception_code[0] != '\0') { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: The server returned exception code '%s'.", exception_code); ++reported_errors_count; } n = n->psNext; if (n != NULL) { n = CPLGetXMLNode(n, "=ServiceException"); } } } else { ret = CE_Failure; } if (orig_root != NULL) { CPLDestroyXMLNode(orig_root); } if (reported_errors_count == 0) { ret = CE_Failure; } return ret; }
DIMAPDataset::~DIMAPDataset() { FlushCache(); CPLDestroyXMLNode( psProduct ); CPLFree( pszGCPProjection ); if( nGCPCount > 0 ) { GDALDeinitGCPs( nGCPCount, pasGCPList ); CPLFree( pasGCPList ); } CSLDestroy(papszXMLDimapMetadata); CloseDependentDatasets(); }
/** * \brief Import coordinate system from XML format (GML only currently). * * This method is the same as the C function OSRImportFromXML() * @param pszXML XML string to import * @return OGRERR_NONE on success or OGRERR_CORRUPT_DATA on failure. */ OGRErr OGRSpatialReference::importFromXML(const char *pszXML) { CPLXMLNode *psTree; OGRErr eErr = OGRERR_UNSUPPORTED_SRS; this->Clear(); /* -------------------------------------------------------------------- */ /* Parse the XML. */ /* -------------------------------------------------------------------- */ psTree = CPLParseXMLString(pszXML); if (psTree == NULL) return OGRERR_CORRUPT_DATA; CPLStripXMLNamespace(psTree, "gml", TRUE); /* -------------------------------------------------------------------- */ /* Import according to the root node type. We walk through */ /* root elements as there is sometimes prefix stuff like */ /* <?xml>. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psNode = psTree; for (psNode = psTree; psNode != NULL; psNode = psNode->psNext) { if (EQUAL(psNode->pszValue, "GeographicCRS")) { eErr = importGeogCSFromXML(this, psNode); break; } else if (EQUAL(psNode->pszValue, "ProjectedCRS")) { eErr = importProjCSFromXML(this, psNode); break; } } CPLDestroyXMLNode(psTree); return eErr; }