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
24 CPL_C_START
25
27 typedef enum
28{
CXT_Element = 0, CXT_Text = 1, CXT_Attribute = 2, CXT_Comment = 3, CXT_Literal = 4
34} CPLXMLNodeType;
35
37 typedef struct CPLXMLNode CPLXMLNode;
38
53 struct CPLXMLNode
54{
61 CPLXMLNodeType eType;
62
84 char *pszValue;
85
93 struct CPLXMLNode *psNext;
94
105 struct CPLXMLNode *psChild;
106};
107
108 CPLXMLNode CPL_DLL *CPLParseXMLString(const char *);
109 void CPL_DLL CPLDestroyXMLNode(CPLXMLNode *);
110 CPLXMLNode CPL_DLL *CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath);
111#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
113 extern "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
124 CPLXMLNode CPL_DLL *CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget);
125#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
127 extern "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
138 const char CPL_DLL *CPLGetXMLValue(const CPLXMLNode *poRoot,
139 const char *pszPath, const char *pszDefault);
140 CPLXMLNode CPL_DLL *CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType,
141 const char *pszText);
142 char CPL_DLL *CPLSerializeXMLTree(const CPLXMLNode *psNode);
143 void CPL_DLL CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
144 int CPL_DLL CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
145 void CPL_DLL CPLAddXMLSibling(CPLXMLNode *psOlderSibling,
146 CPLXMLNode *psNewSibling);
147 CPLXMLNode CPL_DLL *CPLCreateXMLElementAndValue(CPLXMLNode *psParent,
148 const char *pszName,
149 const char *pszValue);
150 void CPL_DLL CPLAddXMLAttributeAndValue(CPLXMLNode *psParent,
151 const char *pszName,
152 const char *pszValue);
153 CPLXMLNode CPL_DLL *CPLCloneXMLTree(const CPLXMLNode *psTree);
154 int CPL_DLL CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath,
155 const char *pszValue);
156 void CPL_DLL CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace,
157 int bRecurse);
158 void CPL_DLL CPLCleanXMLElementName(char *);
159
160 CPLXMLNode CPL_DLL *CPLParseXMLFile(const char *pszFilename);
161 int CPL_DLL CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree,
162 const char *pszFilename);
163
164 size_t CPL_DLL CPLXMLNodeGetRAMUsageEstimate(const CPLXMLNode *psNode);
165
166 CPL_C_END
167
168#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
169
170 extern "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
191 class CPL_DLL CPLXMLTreeCloser
192 : public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
193 {
194 public:
196 explicit CPLXMLTreeCloser(CPLXMLNode *data)
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
Manage a tree of XML nodes so that all nodes are freed when the instance goes out of scope.
Definition cpl_minixml.h:193
CPLXMLTreeCloser::CPLXMLTreeCloser
CPLXMLTreeCloser(CPLXMLNode *data)
Constructor.
Definition cpl_minixml.h:196
CPLSearchXMLNode
CPLXMLNode * CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget)
Search for a node in document.
Definition cpl_minixml.cpp:1457
CPLAddXMLAttributeAndValue
void CPLAddXMLAttributeAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an attribute and text value.
Definition cpl_minixml.cpp:1885
CPLParseXMLString
CPLXMLNode * CPLParseXMLString(const char *)
Parse an XML string into tree form.
Definition cpl_minixml.cpp:595
CPLCreateXMLElementAndValue
CPLXMLNode * CPLCreateXMLElementAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an element and text value.
Definition cpl_minixml.cpp:1847
CPLGetXMLNode
CPLXMLNode * CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath)
Find node by path.
Definition cpl_minixml.cpp:1547
CPLStripXMLNamespace
void CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace, int bRecurse)
Strip indicated namespaces.
Definition cpl_minixml.cpp:2054
CPLCleanXMLElementName
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition cpl_minixml.cpp:2228
CPLSetXMLValue
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition cpl_minixml.cpp:1963
CPLCreateXMLNode
CPLXMLNode * CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType, const char *pszText)
Create an document tree item.
Definition cpl_minixml.cpp:1295
CPLDestroyXMLNode
void CPLDestroyXMLNode(CPLXMLNode *)
Destroy a tree.
Definition cpl_minixml.cpp:1401
CPLGetXMLValue
const char * CPLGetXMLValue(const CPLXMLNode *poRoot, const char *pszPath, const char *pszDefault)
Fetch element/attribute value.
Definition cpl_minixml.cpp:1645
CPLRemoveXMLChild
int CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Remove child node from parent.
Definition cpl_minixml.cpp:1760
CPLAddXMLSibling
void CPLAddXMLSibling(CPLXMLNode *psOlderSibling, CPLXMLNode *psNewSibling)
Add new sibling.
Definition cpl_minixml.cpp:1804
CPLParseXMLFile
CPLXMLNode * CPLParseXMLFile(const char *pszFilename)
Parse XML file into tree.
Definition cpl_minixml.cpp:2122
CPLCloneXMLTree
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition cpl_minixml.cpp:1908
CPLAddXMLChild
void CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Add child node to parent.
Definition cpl_minixml.cpp:1706
CPLXMLNodeType
CPLXMLNodeType
XML node type.
Definition cpl_minixml.h:28
CXT_Literal
@ CXT_Literal
Definition cpl_minixml.h:33
CXT_Element
@ CXT_Element
Definition cpl_minixml.h:29
CXT_Comment
@ CXT_Comment
Definition cpl_minixml.h:32
CXT_Text
@ CXT_Text
Definition cpl_minixml.h:30
CXT_Attribute
@ CXT_Attribute
Definition cpl_minixml.h:31
CPLSerializeXMLTreeToFile
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition cpl_minixml.cpp:2160
CPLXMLNodeGetRAMUsageEstimate
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
CPLSerializeXMLTree
char * CPLSerializeXMLTree(const CPLXMLNode *psNode)
Convert tree into string document.
Definition cpl_minixml.cpp:1251
cpl_port.h
Core portability definitions for CPL.
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
CPLXMLNode
Document node structure.
Definition cpl_minixml.h:54
CPLXMLNode::psChild
struct CPLXMLNode * psChild
Child node.
Definition cpl_minixml.h:105
CPLXMLNode::eType
CPLXMLNodeType eType
Node type.
Definition cpl_minixml.h:61
CPLXMLNode::psNext
struct CPLXMLNode * psNext
Next sibling.
Definition cpl_minixml.h:93
CPLXMLNode::pszValue
char * pszValue
Node value.
Definition cpl_minixml.h:84