static void TrimTree( reg_tree *tree ) /****************************************/ { if( tree->lo != NULL ) { if( !tree->lo->has_name ) { BurnRegTree( tree->lo ); tree->lo = NULL; } else { TrimTree( tree->lo ); } } if( tree->hi != NULL ) { if( !tree->hi->has_name ) { BurnRegTree( tree->hi ); tree->hi = NULL; } else { TrimTree( tree->hi ); } } }
void BuildNameTree( conflict_node *conf ) /******************************************/ { name *temp; reg_tree *tree; temp = conf->name; if( temp->n.class == N_TEMP && temp->t.alias != temp ) { tree = BuildTree( temp, temp, temp->v.offset, temp->n.size, conf ); tree = CheckTree( tree ); if( tree != NULL ) { TrimTree( tree ); } } else {
static int TrimTree( CPLXMLNode * psRoot ) { if( psRoot == NULL ) return FALSE; CPLXMLNode *psChild = psRoot->psChild; // check for id attribute while( psChild != NULL && !( psChild->eType == CXT_Attribute && EQUAL(psChild->pszValue, "gml:id"))) psChild = psChild->psNext; if( psChild != NULL ) return TRUE; // search the child elements of psRoot int bReturn = FALSE, bRemove; for( psChild = psRoot->psChild; psChild != NULL;) { CPLXMLNode* psNextChild = psChild->psNext; if( psChild->eType == CXT_Element ) { bRemove = TrimTree( psChild ); if( bRemove ) { bReturn = bRemove; } else { //remove this child CPLRemoveXMLChild( psRoot, psChild ); CPLDestroyXMLNode( psChild ); } } psChild = psNextChild; } return bReturn; }
static CPLXMLNode *FindTreeByURL( CPLXMLNode *** ppapsRoot, char *** ppapszResourceHREF, const char *pszURL ) { if( *ppapsRoot == NULL || ppapszResourceHREF == NULL ) return NULL; //if found in ppapszResourceHREF int i, nItems; char *pszLocation; if( ( i = CSLFindString( *ppapszResourceHREF, pszURL )) >= 0 ) { //return corresponding psRoot return (*ppapsRoot)[i]; } else { CPLXMLNode *psSrcTree = NULL, *psSibling; pszLocation = CPLStrdup( pszURL ); //if it is part of filesystem if( CPLCheckForFile( pszLocation, NULL) ) {//filesystem psSrcTree = CPLParseXMLFile( pszURL ); } else if( CPLHTTPEnabled() ) {//web resource CPLErrorReset(); CPLHTTPResult *psResult = CPLHTTPFetch( pszURL, NULL ); if( psResult != NULL ) { if( psResult->nDataLen > 0 && CPLGetLastErrorNo() == 0) psSrcTree = CPLParseXMLString( (const char*)psResult->pabyData ); CPLHTTPDestroyResult( psResult ); } } //report error in case the resource cannot be retrieved. if( psSrcTree == NULL ) CPLError( CE_Failure, CPLE_NotSupported, "Could not access %s", pszLocation ); CPLFree( pszLocation ); /************************************************************************/ /* In the external GML resource we will only need elements */ /* identified by a "gml:id". So trim them. */ /************************************************************************/ psSibling = psSrcTree; while( psSibling != NULL ) { TrimTree( psSibling ); psSibling = psSibling->psNext; } //update to lists nItems = CSLCount(*ppapszResourceHREF); *ppapszResourceHREF = CSLAddString( *ppapszResourceHREF, pszURL ); *ppapsRoot = (CPLXMLNode**)CPLRealloc(*ppapsRoot, (nItems+2)*sizeof(CPLXMLNode*)); (*ppapsRoot)[nItems] = psSrcTree; (*ppapsRoot)[nItems+1] = NULL; //return the tree return (*ppapsRoot)[nItems]; } }