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 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef CPL_MINIXML_H_INCLUDED
15#define CPL_MINIXML_H_INCLUDED
16
17#include "cpl_port.h"
18
25 CPL_C_START
26
28 typedef enum
29{
CXT_Element = 0, CXT_Text = 1, CXT_Attribute = 2, CXT_Comment = 3, CXT_Literal = 4
35} CPLXMLNodeType;
36
38 typedef struct CPLXMLNode CPLXMLNode;
39
54 struct CPLXMLNode
55{
62 CPLXMLNodeType eType;
63
85 char *pszValue;
86
94 struct CPLXMLNode *psNext;
95
106 struct CPLXMLNode *psChild;
107};
108
109 CPLXMLNode CPL_DLL *CPLParseXMLString(const char *);
110 void CPL_DLL CPLDestroyXMLNode(CPLXMLNode *);
111 CPLXMLNode CPL_DLL *CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath);
112#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
114 extern "C++"
115{
116 inline const CPLXMLNode *CPLGetXMLNode(const CPLXMLNode *poRoot,
117 const char *pszPath)
118 {
119 return const_cast<const CPLXMLNode *>(
120 CPLGetXMLNode(const_cast<CPLXMLNode *>(poRoot), pszPath));
121 }
122}
124#endif
125 CPLXMLNode CPL_DLL *CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget);
126#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
128 extern "C++"
129{
130 inline const CPLXMLNode *CPLSearchXMLNode(const CPLXMLNode *poRoot,
131 const char *pszTarget)
132 {
133 return const_cast<const CPLXMLNode *>(
134 CPLSearchXMLNode(const_cast<CPLXMLNode *>(poRoot), pszTarget));
135 }
136}
138#endif
139 const char CPL_DLL *CPLGetXMLValue(const CPLXMLNode *poRoot,
140 const char *pszPath, const char *pszDefault);
141 CPLXMLNode CPL_DLL *CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType,
142 const char *pszText);
143 char CPL_DLL *CPLSerializeXMLTree(const CPLXMLNode *psNode);
144 void CPL_DLL CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
145 int CPL_DLL CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
146 void CPL_DLL CPLAddXMLSibling(CPLXMLNode *psOlderSibling,
147 CPLXMLNode *psNewSibling);
148 CPLXMLNode CPL_DLL *CPLCreateXMLElementAndValue(CPLXMLNode *psParent,
149 const char *pszName,
150 const char *pszValue);
151 void CPL_DLL CPLAddXMLAttributeAndValue(CPLXMLNode *psParent,
152 const char *pszName,
153 const char *pszValue);
154 CPLXMLNode CPL_DLL *CPLCloneXMLTree(const CPLXMLNode *psTree);
155 int CPL_DLL CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath,
156 const char *pszValue);
157 void CPL_DLL CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace,
158 int bRecurse);
159 void CPL_DLL CPLCleanXMLElementName(char *);
160
161 CPLXMLNode CPL_DLL *CPLParseXMLFile(const char *pszFilename);
162 int CPL_DLL CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree,
163 const char *pszFilename);
164
165 size_t CPL_DLL CPLXMLNodeGetRAMUsageEstimate(const CPLXMLNode *psNode);
166
167 CPL_C_END
168
169#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
170
171 extern "C++"
172{
173#ifndef DOXYGEN_SKIP
174#include <memory>
175#endif
176
178 struct CPL_DLL CPLXMLTreeCloserDeleter
179 {
180 void operator()(CPLXMLNode *psNode) const
181 {
182 CPLDestroyXMLNode(psNode);
183 }
184 };
185
192 class CPL_DLL CPLXMLTreeCloser
193 : public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
194 {
195 public:
197 explicit CPLXMLTreeCloser(CPLXMLNode *data)
198 : std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>(data)
199 {
200 }
201
204 CPLXMLNode *getDocumentElement();
205 };
206
207} // extern "C++"
208
209#endif /* __cplusplus */
210
211#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:194
CPLXMLTreeCloser::CPLXMLTreeCloser
CPLXMLTreeCloser(CPLXMLNode *data)
Constructor.
Definition cpl_minixml.h:197
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:1886
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:2055
CPLCleanXMLElementName
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition cpl_minixml.cpp:2229
CPLSetXMLValue
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition cpl_minixml.cpp:1964
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:2123
CPLCloneXMLTree
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition cpl_minixml.cpp:1909
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:29
CXT_Literal
@ CXT_Literal
Definition cpl_minixml.h:34
CXT_Element
@ CXT_Element
Definition cpl_minixml.h:30
CXT_Comment
@ CXT_Comment
Definition cpl_minixml.h:33
CXT_Text
@ CXT_Text
Definition cpl_minixml.h:31
CXT_Attribute
@ CXT_Attribute
Definition cpl_minixml.h:32
CPLSerializeXMLTreeToFile
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition cpl_minixml.cpp:2161
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:2279
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:283
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:279
CPLXMLNode
Document node structure.
Definition cpl_minixml.h:55
CPLXMLNode::psChild
struct CPLXMLNode * psChild
Child node.
Definition cpl_minixml.h:106
CPLXMLNode::eType
CPLXMLNodeType eType
Node type.
Definition cpl_minixml.h:62
CPLXMLNode::psNext
struct CPLXMLNode * psNext
Next sibling.
Definition cpl_minixml.h:94
CPLXMLNode::pszValue
char * pszValue
Node value.
Definition cpl_minixml.h:85