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

Function CPLSerializeXMLTreeToFile

port/cpl_minixml.cpp:2160–2208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2158 */
2159
2160int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
2161
2162{
2163 /* -------------------------------------------------------------------- */
2164 /* Serialize document. */
2165 /* -------------------------------------------------------------------- */
2166 char *pszDoc = CPLSerializeXMLTree(psTree);
2167 if (pszDoc == nullptr)
2168 return FALSE;
2169
2170 const vsi_l_offset nLength = strlen(pszDoc);
2171
2172 /* -------------------------------------------------------------------- */
2173 /* Create file. */
2174 /* -------------------------------------------------------------------- */
2175 VSILFILE *fp = VSIFOpenL(pszFilename, "wt");
2176 if (fp == nullptr)
2177 {
2178 CPLError(CE_Failure, CPLE_OpenFailed, "Failed to open %.500s to write.",
2179 pszFilename);
2180 CPLFree(pszDoc);
2181 return FALSE;
2182 }
2183
2184 /* -------------------------------------------------------------------- */
2185 /* Write file. */
2186 /* -------------------------------------------------------------------- */
2187 if (VSIFWriteL(pszDoc, 1, static_cast<size_t>(nLength), fp) != nLength)
2188 {
2189 CPLError(CE_Failure, CPLE_FileIO,
2190 "Failed to write whole XML document (%.500s).", pszFilename);
2191 CPL_IGNORE_RET_VAL(VSIFCloseL(fp));
2192 CPLFree(pszDoc);
2193 return FALSE;
2194 }
2195
2196 /* -------------------------------------------------------------------- */
2197 /* Cleanup */
2198 /* -------------------------------------------------------------------- */
2199 const bool bRet = VSIFCloseL(fp) == 0;
2200 if (!bRet)
2201 {
2202 CPLError(CE_Failure, CPLE_FileIO,
2203 "Failed to write whole XML document (%.500s).", pszFilename);
2204 }
2205 CPLFree(pszDoc);
2206
2207 return bRet;
2208}
2209
2210/************************************************************************/
2211/* CPLCleanXMLElementName() */

Callers 15

OGRWFSJoinLayerMethod · 0.85
~OGRWFSDataSourceMethod · 0.85
OpenMethod · 0.85
LoadMultipleLayerDefnMethod · 0.85
ParseSchemaMethod · 0.85
ResolveXlinksMethod · 0.85
GDALTileIndexInternalFunction · 0.85
CreateGMLJP2V2Method · 0.85
LoadVectorLayersMethod · 0.85
TrySaveXMLMethod · 0.85
SaveMethod · 0.85

Calls 6

CPLSerializeXMLTreeFunction · 0.85
VSIFOpenLFunction · 0.85
CPLErrorFunction · 0.85
VSIFWriteLFunction · 0.85
VSIFCloseLFunction · 0.85
CPL_IGNORE_RET_VALFunction · 0.70

Tested by

no test coverage detected