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
41 CPL_C_START
42
44 typedef enum
45 { CXT_Element = 0, CXT_Text = 1, CXT_Attribute = 2, CXT_Comment = 3, CXT_Literal = 4
51 } CPLXMLNodeType;
52
54 typedef struct CPLXMLNode CPLXMLNode;
69 struct CPLXMLNode
70 {
77 CPLXMLNodeType eType;
78
100 char *pszValue;
101
109 struct CPLXMLNode *psNext;
110
121 struct CPLXMLNode *psChild;
122 };
123
124 CPLXMLNode CPL_DLL *CPLParseXMLString(const char *);
125 void CPL_DLL CPLDestroyXMLNode(CPLXMLNode *);
126 CPLXMLNode CPL_DLL *CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath);
127 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
128
129 extern "C++"
130 {
131 inline const CPLXMLNode *CPLGetXMLNode(const CPLXMLNode *poRoot,
132 const char *pszPath)
133 {
134 return const_cast<const CPLXMLNode *>(
135 CPLGetXMLNode(const_cast<CPLXMLNode *>(poRoot), pszPath));
136 }
137 }
139 #endif
140 CPLXMLNode CPL_DLL *CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget);
141 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
142
143 extern "C++"
144 {
145 inline const CPLXMLNode *CPLSearchXMLNode(const CPLXMLNode *poRoot,
146 const char *pszTarget)
147 {
148 return const_cast<const CPLXMLNode *>(
149 CPLSearchXMLNode(const_cast<CPLXMLNode *>(poRoot), pszTarget));
150 }
151 }
153 #endif
154 const char CPL_DLL *CPLGetXMLValue(const CPLXMLNode *poRoot,
155 const char *pszPath, const char *pszDefault);
156 CPLXMLNode CPL_DLL *CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType,
157 const char *pszText);
158 char CPL_DLL *CPLSerializeXMLTree(const CPLXMLNode *psNode);
159 void CPL_DLL CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
160 int CPL_DLL CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild);
161 void CPL_DLL CPLAddXMLSibling(CPLXMLNode *psOlderSibling,
162 CPLXMLNode *psNewSibling);
163 CPLXMLNode CPL_DLL *CPLCreateXMLElementAndValue(CPLXMLNode *psParent,
164 const char *pszName,
165 const char *pszValue);
166 void CPL_DLL CPLAddXMLAttributeAndValue(CPLXMLNode *psParent,
167 const char *pszName,
168 const char *pszValue);
169 CPLXMLNode CPL_DLL *CPLCloneXMLTree(const CPLXMLNode *psTree);
170 int CPL_DLL CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath,
171 const char *pszValue);
172 void CPL_DLL CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace,
173 int bRecurse);
174 void CPL_DLL CPLCleanXMLElementName(char *);
175
176 CPLXMLNode CPL_DLL *CPLParseXMLFile(const char *pszFilename);
177 int CPL_DLL CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree,
178 const char *pszFilename);
179
180 CPL_C_END
181
182 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
183
184 extern "C++"
185 {
186 #ifndef DOXYGEN_SKIP
187 #include <memory>
188 #endif
189
191 struct CPL_DLL CPLXMLTreeCloserDeleter
192 {
193 void operator()(CPLXMLNode *psNode) const
194 {
195 CPLDestroyXMLNode(psNode);
196 }
197 };
204 class CPL_DLL CPLXMLTreeCloser
205 : public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
206 {
207 public:
209 explicit CPLXMLTreeCloser(CPLXMLNode *data)
210 : std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>(data)
211 {
212 }
213
216 CPLXMLNode *getDocumentElement();
217 };
218
219 } // extern "C++"
220
221 #endif /* __cplusplus */
222
223 #endif /* CPL_MINIXML_H_INCLUDED */
CXT_Element
@ CXT_Element
Definition: cpl_minixml.h:46
CPLRemoveXMLChild
int CPLRemoveXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Remove child node from parent.
Definition: cpl_minixml.cpp:1776
CPLParseXMLFile
CPLXMLNode * CPLParseXMLFile(const char *pszFilename)
Parse XML file into tree.
Definition: cpl_minixml.cpp:2139
CPLSetXMLValue
int CPLSetXMLValue(CPLXMLNode *psRoot, const char *pszPath, const char *pszValue)
Set element value by path.
Definition: cpl_minixml.cpp:1980
CPLCleanXMLElementName
void CPLCleanXMLElementName(char *)
Make string into safe XML token.
Definition: cpl_minixml.cpp:2245
CXT_Comment
@ CXT_Comment
Definition: cpl_minixml.h:49
CPLSearchXMLNode
CPLXMLNode * CPLSearchXMLNode(CPLXMLNode *poRoot, const char *pszTarget)
Search for a node in document.
Definition: cpl_minixml.cpp:1473
CPLParseXMLString
CPLXMLNode * CPLParseXMLString(const char *)
Parse an XML string into tree form.
Definition: cpl_minixml.cpp:611
CXT_Text
@ CXT_Text
Definition: cpl_minixml.h:47
CPLXMLNode
Document node structure.
Definition: cpl_minixml.h:69
CPLXMLTreeCloser::CPLXMLTreeCloser
CPLXMLTreeCloser(CPLXMLNode *data)
Constructor.
Definition: cpl_minixml.h:209
CPLXMLNodeType
CPLXMLNodeType
XML node type.
Definition: cpl_minixml.h:44
CXT_Literal
@ CXT_Literal
Definition: cpl_minixml.h:50
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:306
CPLCloneXMLTree
CPLXMLNode * CPLCloneXMLTree(const CPLXMLNode *psTree)
Copy tree.
Definition: cpl_minixml.cpp:1925
CPLSerializeXMLTree
char * CPLSerializeXMLTree(const CPLXMLNode *psNode)
Convert tree into string document.
Definition: cpl_minixml.cpp:1267
CPLAddXMLAttributeAndValue
void CPLAddXMLAttributeAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an attribute and text value.
Definition: cpl_minixml.cpp:1902
CPLXMLTreeCloser
Manage a tree of XML nodes so that all nodes are freed when the instance goes out of scope.
Definition: cpl_minixml.h:204
CPLGetXMLNode
CPLXMLNode * CPLGetXMLNode(CPLXMLNode *poRoot, const char *pszPath)
Find node by path.
Definition: cpl_minixml.cpp:1563
CPLSerializeXMLTreeToFile
int CPLSerializeXMLTreeToFile(const CPLXMLNode *psTree, const char *pszFilename)
Write document tree to a file.
Definition: cpl_minixml.cpp:2177
CPLXMLNode::eType
CPLXMLNodeType eType
Node type.
Definition: cpl_minixml.h:77
CPLDestroyXMLNode
void CPLDestroyXMLNode(CPLXMLNode *)
Destroy a tree.
Definition: cpl_minixml.cpp:1417
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:310
CPLAddXMLChild
void CPLAddXMLChild(CPLXMLNode *psParent, CPLXMLNode *psChild)
Add child node to parent.
Definition: cpl_minixml.cpp:1722
CPLGetXMLValue
const char * CPLGetXMLValue(const CPLXMLNode *poRoot, const char *pszPath, const char *pszDefault)
Fetch element/attribute value.
Definition: cpl_minixml.cpp:1661
CXT_Attribute
@ CXT_Attribute
Definition: cpl_minixml.h:48
CPLCreateXMLNode
CPLXMLNode * CPLCreateXMLNode(CPLXMLNode *poParent, CPLXMLNodeType eType, const char *pszText)
Create an document tree item.
Definition: cpl_minixml.cpp:1311
CPLStripXMLNamespace
void CPLStripXMLNamespace(CPLXMLNode *psRoot, const char *pszNameSpace, int bRecurse)
Strip indicated namespaces.
Definition: cpl_minixml.cpp:2071
CPLXMLNode::psNext
struct CPLXMLNode * psNext
Next sibling.
Definition: cpl_minixml.h:109
cpl_port.h
CPLCreateXMLElementAndValue
CPLXMLNode * CPLCreateXMLElementAndValue(CPLXMLNode *psParent, const char *pszName, const char *pszValue)
Create an element and text value.
Definition: cpl_minixml.cpp:1863
CPLXMLNode::pszValue
char * pszValue
Node value.
Definition: cpl_minixml.h:100
CPLXMLNode::psChild
struct CPLXMLNode * psChild
Child node.
Definition: cpl_minixml.h:121
CPLAddXMLSibling
void CPLAddXMLSibling(CPLXMLNode *psOlderSibling, CPLXMLNode *psNewSibling)
Add new sibling.
Definition: cpl_minixml.cpp:1820