GDAL
cpl_minixml.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cpl_minixml.h df507edcc67aa14ada1432baf516f49e6557fb06 2018-04-10 15:26:13 +0200 Even Rouault $
3  *
4  * Project: CPL - Common Portability Library
5  * Purpose: Declarations for MiniXML Handler.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  **********************************************************************
9  * Copyright (c) 2001, Frank Warmerdam
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef CPL_MINIXML_H_INCLUDED
31 #define CPL_MINIXML_H_INCLUDED
32 
33 #include "cpl_port.h"
34 
42 
44 typedef enum
52 
66 typedef struct CPLXMLNode
67 {
75 
97  char *pszValue;
98 
107 
119 } CPLXMLNode;
120 
121 CPLXMLNode CPL_DLL *CPLParseXMLString( const char * );
122 void CPL_DLL CPLDestroyXMLNode( CPLXMLNode * );
123 CPLXMLNode CPL_DLL *CPLGetXMLNode( CPLXMLNode *poRoot,
124  const char *pszPath );
125 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
126 
127 extern "C++"
128 {
129 inline const CPLXMLNode *CPLGetXMLNode( const CPLXMLNode *poRoot,
130  const char *pszPath ) {
131  return const_cast<const CPLXMLNode*>(CPLGetXMLNode(
132  const_cast<CPLXMLNode*>(poRoot), pszPath));
133 }
134 }
136 #endif
137 CPLXMLNode CPL_DLL *CPLSearchXMLNode( CPLXMLNode *poRoot,
138  const char *pszTarget );
139 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
140 
141 extern "C++"
142 {
143 inline const CPLXMLNode *CPLSearchXMLNode( const CPLXMLNode *poRoot,
144  const char *pszTarget ) {
145  return const_cast<const CPLXMLNode*>(CPLSearchXMLNode(
146  const_cast<CPLXMLNode*>(poRoot), pszTarget));
147 }
148 }
150 #endif
151 const char CPL_DLL *CPLGetXMLValue( const CPLXMLNode *poRoot,
152  const char *pszPath,
153  const char *pszDefault );
154 CPLXMLNode CPL_DLL *CPLCreateXMLNode( CPLXMLNode *poParent,
156  const char *pszText );
157 char CPL_DLL *CPLSerializeXMLTree( const CPLXMLNode *psNode );
158 void CPL_DLL CPLAddXMLChild( CPLXMLNode *psParent,
159  CPLXMLNode *psChild );
160 int CPL_DLL CPLRemoveXMLChild( CPLXMLNode *psParent,
161  CPLXMLNode *psChild );
162 void CPL_DLL CPLAddXMLSibling( CPLXMLNode *psOlderSibling,
163  CPLXMLNode *psNewSibling );
165  const char *pszName,
166  const char *pszValue );
167 void CPL_DLL CPLAddXMLAttributeAndValue( CPLXMLNode *psParent,
168  const char *pszName,
169  const char *pszValue );
170 CPLXMLNode CPL_DLL *CPLCloneXMLTree( const CPLXMLNode *psTree );
171 int CPL_DLL CPLSetXMLValue( CPLXMLNode *psRoot, const char *pszPath,
172  const char *pszValue );
173 void CPL_DLL CPLStripXMLNamespace( CPLXMLNode *psRoot,
174  const char *pszNameSpace,
175  int bRecurse );
176 void CPL_DLL CPLCleanXMLElementName( char * );
177 
178 CPLXMLNode CPL_DLL *CPLParseXMLFile( const char *pszFilename );
179 int CPL_DLL CPLSerializeXMLTreeToFile( const CPLXMLNode *psTree,
180  const char *pszFilename );
181 
182 CPL_C_END
183 
184 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
185 
186 extern "C++"
187 {
188 #ifndef DOXYGEN_SKIP
189 #include <memory>
190 #endif
191 
193 struct CPLXMLTreeCloserDeleter
194 {
195  void operator()(CPLXMLNode* psNode) const { CPLDestroyXMLNode(psNode); }
196 };
202 class CPLXMLTreeCloser: public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
203 {
204  public:
206  explicit CPLXMLTreeCloser(CPLXMLNode* data):
207  std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>(data) {}
208 
211  CPLXMLNode* getDocumentElement();
212 };
213 
214 } // extern "C++"
215 
216 #endif /* __cplusplus */
217 
218 #endif /* CPL_MINIXML_H_INCLUDED */
CPLXMLNode * CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType, const char *pszText)
Create an document tree item.
Definition: cpl_minixml.cpp:1297
void CPLAddXMLAttributeAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an attribute and text value.
Definition: cpl_minixml.cpp:1890
Definition: cpl_minixml.h:47
CPLXMLNode * CPLParseXMLFile(const char *pszFilename)
Parse XML file into tree.
Definition: cpl_minixml.cpp:2131
Document node structure.
Definition: cpl_minixml.h:66
int CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Remove child node from parent.
Definition: cpl_minixml.cpp:1763
Core portability definitions for CPL.
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:337
Definition: cpl_minixml.h:46
void CPLAddXMLSibling(CPLXMLNode *psOlderSibling, CPLXMLNode *psNewSibling)
Add new sibling.
Definition: cpl_minixml.cpp:1808
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition: cpl_minixml.cpp:1969
CPLXMLNode * CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget)
Search for a node in document.
Definition: cpl_minixml.cpp:1468
const char * CPLGetXMLValue(const CPLXMLNode *poRoot, const char *pszPath, const char *pszDefault)
Fetch element/attribute value.
Definition: cpl_minixml.cpp:1645
void CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace, int bRecurse)
Strip indicated namespaces.
Definition: cpl_minixml.cpp:2061
char * CPLSerializeXMLTree(const CPLXMLNode *psNode)
Convert tree into string document.
Definition: cpl_minixml.cpp:1252
void CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Add child node to parent.
Definition: cpl_minixml.cpp:1707
CPLXMLNodeType eType
Node type.
Definition: cpl_minixml.h:74
struct CPLXMLNode CPLXMLNode
Document node structure.
CPLXMLNode * CPLParseXMLString(const char *)
Parse an XML string into tree form.
Definition: cpl_minixml.cpp:614
Definition: cpl_minixml.h:50
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition: cpl_minixml.cpp:2169
Definition: cpl_minixml.h:48
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition: cpl_minixml.cpp:1914
Manage a tree of XML nodes so that all nodes are freed when the instance goes out of scope...
Definition: cpl_minixml.h:202
void CPLDestroyXMLNode(CPLXMLNode *)
Destroy a tree.
Definition: cpl_minixml.cpp:1412
struct CPLXMLNode * psNext
Next sibling.
Definition: cpl_minixml.h:106
CPLXMLTreeCloser(CPLXMLNode *data)
Constructor.
Definition: cpl_minixml.h:206
CPLXMLNodeType
XML node type.
Definition: cpl_minixml.h:44
Definition: cpl_minixml.h:49
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition: cpl_minixml.cpp:2240
CPLXMLNode * CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath)
Find node by path.
Definition: cpl_minixml.cpp:1557
char * pszValue
Node value.
Definition: cpl_minixml.h:97
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:339
struct CPLXMLNode * psChild
Child node.
Definition: cpl_minixml.h:118
CPLXMLNode * CPLCreateXMLElementAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an element and text value.
Definition: cpl_minixml.cpp:1851

Generated for GDAL by doxygen 1.8.13.