GDAL
cpl_minixml.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id$
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 
54 typedef struct CPLXMLNode CPLXMLNode;
55 
70 struct CPLXMLNode
71 {
79 
101  char *pszValue;
102 
111 
123 };
124 
125 CPLXMLNode CPL_DLL *CPLParseXMLString(const char *);
126 void CPL_DLL CPLDestroyXMLNode(CPLXMLNode *);
127 CPLXMLNode CPL_DLL *CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath);
128 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
130 extern "C++"
131 {
132  inline const CPLXMLNode *CPLGetXMLNode(const CPLXMLNode *poRoot,
133  const char *pszPath)
134  {
135  return const_cast<const CPLXMLNode *>(
136  CPLGetXMLNode(const_cast<CPLXMLNode *>(poRoot), pszPath));
137  }
138 }
140 #endif
141 CPLXMLNode CPL_DLL *CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget);
142 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
144 extern "C++"
145 {
146  inline const CPLXMLNode *CPLSearchXMLNode(const CPLXMLNode *poRoot,
147  const char *pszTarget)
148  {
149  return const_cast<const CPLXMLNode *>(
150  CPLSearchXMLNode(const_cast<CPLXMLNode *>(poRoot), pszTarget));
151  }
152 }
154 #endif
155 const char CPL_DLL *CPLGetXMLValue(const CPLXMLNode *poRoot,
156  const char *pszPath, const char *pszDefault);
158  const char *pszText);
159 char CPL_DLL *CPLSerializeXMLTree(const CPLXMLNode *psNode);
160 void CPL_DLL CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
161 int CPL_DLL CPLRemoveXMLChild(CPLXMLNode *psParent, 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, const char *pszNameSpace,
174  int bRecurse);
175 void CPL_DLL CPLCleanXMLElementName(char *);
176 
177 CPLXMLNode CPL_DLL *CPLParseXMLFile(const char *pszFilename);
178 int CPL_DLL CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree,
179  const char *pszFilename);
180 
181 size_t CPL_DLL CPLXMLNodeGetRAMUsageEstimate(const CPLXMLNode *psNode);
182 
183 CPL_C_END
184 
185 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
186 
187 extern "C++"
188 {
189 #ifndef DOXYGEN_SKIP
190 #include <memory>
191 #endif
192 
194  struct CPL_DLL CPLXMLTreeCloserDeleter
195  {
196  void operator()(CPLXMLNode *psNode) const
197  {
198  CPLDestroyXMLNode(psNode);
199  }
200  };
201 
208  class CPL_DLL CPLXMLTreeCloser
209  : public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
210  {
211  public:
213  explicit CPLXMLTreeCloser(CPLXMLNode *data)
214  : std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>(data)
215  {
216  }
217 
220  CPLXMLNode *getDocumentElement();
221  };
222 
223 } // extern "C++"
224 
225 #endif /* __cplusplus */
226 
227 #endif /* CPL_MINIXML_H_INCLUDED */
Manage a tree of XML nodes so that all nodes are freed when the instance goes out of scope.
Definition: cpl_minixml.h:210
CPLXMLTreeCloser(CPLXMLNode *data)
Constructor.
Definition: cpl_minixml.h:213
void CPLAddXMLAttributeAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an attribute and text value.
Definition: cpl_minixml.cpp:1902
char * CPLSerializeXMLTree(const CPLXMLNode *psNode)
Convert tree into string document.
Definition: cpl_minixml.cpp:1267
void CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace, int bRecurse)
Strip indicated namespaces.
Definition: cpl_minixml.cpp:2071
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition: cpl_minixml.cpp:2245
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition: cpl_minixml.cpp:1980
CPLXMLNode * CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType, const char *pszText)
Create an document tree item.
Definition: cpl_minixml.cpp:1311
void CPLDestroyXMLNode(CPLXMLNode *)
Destroy a tree.
Definition: cpl_minixml.cpp:1417
CPLXMLNode * CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget)
Search for a node in document.
Definition: cpl_minixml.cpp:1473
int CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Remove child node from parent.
Definition: cpl_minixml.cpp:1776
void CPLAddXMLSibling(CPLXMLNode *psOlderSibling, CPLXMLNode *psNewSibling)
Add new sibling.
Definition: cpl_minixml.cpp:1820
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition: cpl_minixml.cpp:1925
const char * CPLGetXMLValue(const CPLXMLNode *poRoot, const char *pszPath, const char *pszDefault)
Fetch element/attribute value.
Definition: cpl_minixml.cpp:1661
CPLXMLNode * CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath)
Find node by path.
Definition: cpl_minixml.cpp:1563
void CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Add child node to parent.
Definition: cpl_minixml.cpp:1722
CPLXMLNode * CPLParseXMLString(const char *)
Parse an XML string into tree form.
Definition: cpl_minixml.cpp:611
CPLXMLNodeType
XML node type.
Definition: cpl_minixml.h:45
@ CXT_Literal
Definition: cpl_minixml.h:50
@ CXT_Element
Definition: cpl_minixml.h:46
@ CXT_Comment
Definition: cpl_minixml.h:49
@ CXT_Text
Definition: cpl_minixml.h:47
@ CXT_Attribute
Definition: cpl_minixml.h:48
CPLXMLNode * CPLParseXMLFile(const char *pszFilename)
Parse XML file into tree.
Definition: cpl_minixml.cpp:2139
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition: cpl_minixml.cpp:2177
size_t CPLXMLNodeGetRAMUsageEstimate(const CPLXMLNode *psNode)
Return a conservative estimate of the RAM usage of this node, its children and siblings.
Definition: cpl_minixml.cpp:2295
CPLXMLNode * CPLCreateXMLElementAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an element and text value.
Definition: cpl_minixml.cpp:1863
Core portability definitions for CPL.
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:299
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:295
Document node structure.
Definition: cpl_minixml.h:71
struct CPLXMLNode * psChild
Child node.
Definition: cpl_minixml.h:122
CPLXMLNodeType eType
Node type.
Definition: cpl_minixml.h:78
struct CPLXMLNode * psNext
Next sibling.
Definition: cpl_minixml.h:110
char * pszValue
Node value.
Definition: cpl_minixml.h:101