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
26
36
38typedef struct CPLXMLNode CPLXMLNode;
39
55{
63
85 char *pszValue;
86
95
107};
108
109CPLXMLNode CPL_DLL *CPLParseXMLString(const char *);
110void CPL_DLL CPLDestroyXMLNode(CPLXMLNode *);
111CPLXMLNode CPL_DLL *CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath);
112#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
114extern "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
125CPLXMLNode CPL_DLL *CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget);
126#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
128extern "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
139const char CPL_DLL *CPLGetXMLValue(const CPLXMLNode *poRoot,
140 const char *pszPath, const char *pszDefault);
142 const char *pszText);
143char CPL_DLL *CPLSerializeXMLTree(const CPLXMLNode *psNode);
144void CPL_DLL CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
145int CPL_DLL CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
146void CPL_DLL CPLAddXMLSibling(CPLXMLNode *psOlderSibling,
147 CPLXMLNode *psNewSibling);
149 const char *pszName,
150 const char *pszValue);
151void CPL_DLL CPLAddXMLAttributeAndValue(CPLXMLNode *psParent,
152 const char *pszName,
153 const char *pszValue);
154CPLXMLNode CPL_DLL *CPLCloneXMLTree(const CPLXMLNode *psTree);
155int CPL_DLL CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath,
156 const char *pszValue);
157void CPL_DLL CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace,
158 int bRecurse);
159void CPL_DLL CPLCleanXMLElementName(char *);
160
161CPLXMLNode CPL_DLL *CPLParseXMLFile(const char *pszFilename);
162int CPL_DLL CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree,
163 const char *pszFilename);
164
165size_t CPL_DLL CPLXMLNodeGetRAMUsageEstimate(const CPLXMLNode *psNode);
166
168
169#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
170
171extern "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:
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 */
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(CPLXMLNode *data)
Constructor.
Definition cpl_minixml.h:197
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:1886
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:2055
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition cpl_minixml.cpp:2229
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition cpl_minixml.cpp:1964
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:2123
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition cpl_minixml.cpp:1909
void CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Add child node to parent.
Definition cpl_minixml.cpp:1706
CPLXMLNodeType
XML node type.
Definition cpl_minixml.h:29
@ CXT_Literal
Definition cpl_minixml.h:34
@ CXT_Element
Definition cpl_minixml.h:30
@ CXT_Comment
Definition cpl_minixml.h:33
@ CXT_Text
Definition cpl_minixml.h:31
@ CXT_Attribute
Definition cpl_minixml.h:32
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition cpl_minixml.cpp:2161
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
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:283
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:279
Document node structure.
Definition cpl_minixml.h:55
struct CPLXMLNode * psChild
Child node.
Definition cpl_minixml.h:106
CPLXMLNodeType eType
Node type.
Definition cpl_minixml.h:62
struct CPLXMLNode * psNext
Next sibling.
Definition cpl_minixml.h:94
char * pszValue
Node value.
Definition cpl_minixml.h:85