GDAL
cpl_minixml.h
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * Project: CPL - Common Portability Library
4 * Purpose: Declarations for MiniXML Handler.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 **********************************************************************
8 * Copyright (c) 2001, Frank Warmerdam
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef CPL_MINIXML_H_INCLUDED
14#define CPL_MINIXML_H_INCLUDED
15
16#include "cpl_port.h"
17
23
25
27typedef enum
35
37typedef struct CPLXMLNode CPLXMLNode;
38
40
54{
62
84 char *pszValue;
85
94
104
106};
107
108CPLXMLNode CPL_DLL *CPLParseXMLString(const char *);
109void CPL_DLL CPLDestroyXMLNode(CPLXMLNode *);
110CPLXMLNode CPL_DLL *CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath);
111#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
113extern "C++"
114{
115 inline const CPLXMLNode *CPLGetXMLNode(const CPLXMLNode *poRoot,
116 const char *pszPath)
117 {
118 return const_cast<const CPLXMLNode *>(
119 CPLGetXMLNode(const_cast<CPLXMLNode *>(poRoot), pszPath));
120 }
121}
123#endif
124CPLXMLNode CPL_DLL *CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget);
125#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
127extern "C++"
128{
129 inline const CPLXMLNode *CPLSearchXMLNode(const CPLXMLNode *poRoot,
130 const char *pszTarget)
131 {
132 return const_cast<const CPLXMLNode *>(
133 CPLSearchXMLNode(const_cast<CPLXMLNode *>(poRoot), pszTarget));
134 }
135}
137#endif
138const char CPL_DLL *CPLGetXMLValue(const CPLXMLNode *poRoot,
139 const char *pszPath, const char *pszDefault);
140CPLXMLNode CPL_DLL *CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType,
141 const char *pszText);
142char CPL_DLL *CPLSerializeXMLTree(const CPLXMLNode *psNode);
143void CPL_DLL CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
144int CPL_DLL CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
145void CPL_DLL CPLAddXMLSibling(CPLXMLNode *psOlderSibling,
146 CPLXMLNode *psNewSibling);
148 const char *pszName,
149 const char *pszValue);
150void CPL_DLL CPLAddXMLAttributeAndValue(CPLXMLNode *psParent,
151 const char *pszName,
152 const char *pszValue);
153CPLXMLNode CPL_DLL *CPLCloneXMLTree(const CPLXMLNode *psTree);
154int CPL_DLL CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath,
155 const char *pszValue);
156void CPL_DLL CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace,
157 int bRecurse);
158void CPL_DLL CPLCleanXMLElementName(char *);
159
160CPLXMLNode CPL_DLL *CPLParseXMLFile(const char *pszFilename);
161int CPL_DLL CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree,
162 const char *pszFilename);
163
164size_t CPL_DLL CPLXMLNodeGetRAMUsageEstimate(const CPLXMLNode *psNode);
165
167
168#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
169
170extern "C++"
171{
172#ifndef DOXYGEN_SKIP
173#include <memory>
174#endif
175
177 struct CPL_DLL CPLXMLTreeCloserDeleter
178 {
179 void operator()(CPLXMLNode *psNode) const
180 {
181 CPLDestroyXMLNode(psNode);
182 }
183 };
184
186
191 class CPL_DLL CPLXMLTreeCloser
192 : public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
193 {
194 public:
197 : std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>(data)
198 {
199 }
200
203 CPLXMLNode *getDocumentElement();
204 };
205
206} // extern "C++"
207
208#endif /* __cplusplus */
209
210#endif /* CPL_MINIXML_H_INCLUDED */
CPLXMLTreeCloser(CPLXMLNode *data)
Constructor.
Definition cpl_minixml.h:196
CPLXMLNode * CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget)
Search for a node in document.
Definition cpl_minixml.cpp:1457
void CPLAddXMLAttributeAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an attribute and text value.
Definition cpl_minixml.cpp:1885
CPLXMLNode * CPLParseXMLString(const char *)
Parse an XML string into tree form.
Definition cpl_minixml.cpp:595
CPLXMLNode * CPLCreateXMLElementAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an element and text value.
Definition cpl_minixml.cpp:1847
CPLXMLNode * CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath)
Find node by path.
Definition cpl_minixml.cpp:1547
void CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace, int bRecurse)
Strip indicated namespaces.
Definition cpl_minixml.cpp:2054
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition cpl_minixml.cpp:2228
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition cpl_minixml.cpp:1963
CPLXMLNode * CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType, const char *pszText)
Create an document tree item.
Definition cpl_minixml.cpp:1295
void CPLDestroyXMLNode(CPLXMLNode *)
Destroy a tree.
Definition cpl_minixml.cpp:1401
const char * CPLGetXMLValue(const CPLXMLNode *poRoot, const char *pszPath, const char *pszDefault)
Fetch element/attribute value.
Definition cpl_minixml.cpp:1645
int CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Remove child node from parent.
Definition cpl_minixml.cpp:1760
void CPLAddXMLSibling(CPLXMLNode *psOlderSibling, CPLXMLNode *psNewSibling)
Add new sibling.
Definition cpl_minixml.cpp:1804
CPLXMLNode * CPLParseXMLFile(const char *pszFilename)
Parse XML file into tree.
Definition cpl_minixml.cpp:2122
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition cpl_minixml.cpp:1908
void CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Add child node to parent.
Definition cpl_minixml.cpp:1706
CPLXMLNodeType
XML node type.
Definition cpl_minixml.h:28
@ CXT_Literal
Definition cpl_minixml.h:33
@ CXT_Element
Definition cpl_minixml.h:29
@ CXT_Comment
Definition cpl_minixml.h:32
@ CXT_Text
Definition cpl_minixml.h:30
@ CXT_Attribute
Definition cpl_minixml.h:31
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition cpl_minixml.cpp:2160
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:2278
char * CPLSerializeXMLTree(const CPLXMLNode *psNode)
Convert tree into string document.
Definition cpl_minixml.cpp:1251
Core portability definitions for CPL.
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
Document node structure.
Definition cpl_minixml.h:54
struct CPLXMLNode * psChild
Child node.
Definition cpl_minixml.h:105
CPLXMLNodeType eType
Node type.
Definition cpl_minixml.h:61
struct CPLXMLNode * psNext
Next sibling.
Definition cpl_minixml.h:93
char * pszValue
Node value.
Definition cpl_minixml.h:84