cpl_minixml.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**********************************************************************
  2. * $Id: cpl_minixml.h 28690 2015-03-08 20:06:12Z rouault $
  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. #ifndef _CPL_MINIXML_H_INCLUDED
  30. #define _CPL_MINIXML_H_INCLUDED
  31. #include "cpl_port.h"
  32. /**
  33. * \file cpl_minixml.h
  34. *
  35. * Definitions for CPL mini XML Parser/Serializer.
  36. */
  37. CPL_C_START
  38. typedef enum
  39. {
  40. /*! Node is an element */ CXT_Element = 0,
  41. /*! Node is a raw text value */ CXT_Text = 1,
  42. /*! Node is attribute */ CXT_Attribute = 2,
  43. /*! Node is an XML comment. */ CXT_Comment = 3,
  44. /*! Node is a special literal */ CXT_Literal = 4
  45. } CPLXMLNodeType;
  46. /**
  47. * Document node structure.
  48. *
  49. * This C structure is used to hold a single text fragment representing a
  50. * component of the document when parsed. It should be allocated with the
  51. * appropriate CPL function, and freed with CPLDestroyXMLNode(). The structure
  52. * contents should not normally be altered by application code, but may be
  53. * freely examined by application code.
  54. *
  55. * Using the psChild and psNext pointers, a heirarchical tree structure
  56. * for a document can be represented as a tree of CPLXMLNode structures.
  57. */
  58. typedef struct CPLXMLNode
  59. {
  60. /**
  61. * \brief Node type
  62. *
  63. * One of CXT_Element, CXT_Text, CXT_Attribute, CXT_Comment,
  64. * or CXT_Literal.
  65. */
  66. CPLXMLNodeType eType;
  67. /**
  68. * \brief Node value
  69. *
  70. * For CXT_Element this is the name of the element, without the angle
  71. * brackets. Note there is a single CXT_Element even when the document
  72. * contains a start and end element tag. The node represents the pair.
  73. * All text or other elements between the start and end tag will appear
  74. * as children nodes of this CXT_Element node.
  75. *
  76. * For CXT_Attribute the pszValue is the attribute name. The value of
  77. * the attribute will be a CXT_Text child.
  78. *
  79. * For CXT_Text this is the text itself (value of an attribute, or a
  80. * text fragment between an element start and end tags.
  81. *
  82. * For CXT_Literal it is all the literal text. Currently this is just
  83. * used for !DOCTYPE lines, and the value would be the entire line.
  84. *
  85. * For CXT_Comment the value is all the literal text within the comment,
  86. * but not including the comment start/end indicators ("<--" and "-->").
  87. */
  88. char *pszValue;
  89. /**
  90. * \brief Next sibling.
  91. *
  92. * Pointer to next sibling, that is the next node appearing after this
  93. * one that has the same parent as this node. NULL if this node is the
  94. * last child of the parent element.
  95. */
  96. struct CPLXMLNode *psNext;
  97. /**
  98. * \brief Child node.
  99. *
  100. * Pointer to first child node, if any. Only CXT_Element and CXT_Attribute
  101. * nodes should have children. For CXT_Attribute it should be a single
  102. * CXT_Text value node, while CXT_Element can have any kind of child.
  103. * The full list of children for a node are identified by walking the
  104. * psNext's starting with the psChild node.
  105. */
  106. struct CPLXMLNode *psChild;
  107. } CPLXMLNode;
  108. CPLXMLNode CPL_DLL *CPLParseXMLString( const char * );
  109. void CPL_DLL CPLDestroyXMLNode( CPLXMLNode * );
  110. CPLXMLNode CPL_DLL *CPLGetXMLNode( CPLXMLNode *poRoot,
  111. const char *pszPath );
  112. CPLXMLNode CPL_DLL *CPLSearchXMLNode( CPLXMLNode *poRoot,
  113. const char *pszTarget );
  114. const char CPL_DLL *CPLGetXMLValue( CPLXMLNode *poRoot,
  115. const char *pszPath,
  116. const char *pszDefault );
  117. CPLXMLNode CPL_DLL *CPLCreateXMLNode( CPLXMLNode *poParent,
  118. CPLXMLNodeType eType,
  119. const char *pszText );
  120. char CPL_DLL *CPLSerializeXMLTree( const CPLXMLNode *psNode );
  121. void CPL_DLL CPLAddXMLChild( CPLXMLNode *psParent,
  122. CPLXMLNode *psChild );
  123. int CPL_DLL CPLRemoveXMLChild( CPLXMLNode *psParent,
  124. CPLXMLNode *psChild );
  125. void CPL_DLL CPLAddXMLSibling( CPLXMLNode *psOlderSibling,
  126. CPLXMLNode *psNewSibling );
  127. CPLXMLNode CPL_DLL *CPLCreateXMLElementAndValue( CPLXMLNode *psParent,
  128. const char *pszName,
  129. const char *pszValue );
  130. void CPL_DLL CPLAddXMLAttributeAndValue( CPLXMLNode *psParent,
  131. const char *pszName,
  132. const char *pszValue );
  133. CPLXMLNode CPL_DLL *CPLCloneXMLTree( CPLXMLNode *psTree );
  134. int CPL_DLL CPLSetXMLValue( CPLXMLNode *psRoot, const char *pszPath,
  135. const char *pszValue );
  136. void CPL_DLL CPLStripXMLNamespace( CPLXMLNode *psRoot,
  137. const char *pszNameSpace,
  138. int bRecurse );
  139. void CPL_DLL CPLCleanXMLElementName( char * );
  140. CPLXMLNode CPL_DLL *CPLParseXMLFile( const char *pszFilename );
  141. int CPL_DLL CPLSerializeXMLTreeToFile( const CPLXMLNode *psTree,
  142. const char *pszFilename );
  143. CPL_C_END
  144. #endif /* _CPL_MINIXML_H_INCLUDED */