You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

895 lines
44 KiB

7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
7 years ago
​
​
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
​
​
7 years ago
7 years ago
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
7 years ago
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
7 years ago
7 years ago
​
​
7 years ago
7 years ago
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /****************************************************************************/
  2. /*! \mainpage XMLParser library
  3. * \section intro_sec Introduction
  4. *
  5. * This is a basic XML parser written in ANSI C++ for portability.
  6. * It works by using recursion and a node tree for breaking
  7. * down the elements of an XML document.
  8. * Copyright (c) 2002, Frank Vanden Berghen
  9. * All rights reserved.
  10. *
  11. * The following license terms apply to projects that are in some way related to
  12. * the "GINKGO project", including applications
  13. * using "GINKGO project" and tools developed
  14. * for enhancing "GINKGO project". All other projects
  15. * (not related to "GINKGO project") have to use this
  16. * code under the Aladdin Free Public License (AFPL)
  17. * See the file "AFPL-license.txt" for more informations about the AFPL license.
  18. * (see http://www.artifex.com/downloads/doc/Public.htm for detailed AFPL terms)
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions are met:
  22. * * Redistributions of source code must retain the above copyright
  23. * notice, this list of conditions and the following disclaimer.
  24. * * Redistributions in binary form must reproduce the above copyright
  25. * notice, this list of conditions and the following disclaimer in the
  26. * documentation and/or other materials provided with the distribution.
  27. * * Neither the name of Frank Vanden Berghen nor the
  28. * names of its contributors may be used to endorse or promote products
  29. * derived from this software without specific prior written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY Frank Vanden Berghen ``AS IS'' AND ANY
  32. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  33. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  34. * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  35. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  38. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41. *
  42. * @version V2.39
  43. * @author Frank Vanden Berghen
  44. *
  45. * \section tutorial First Tutorial
  46. * You can follow a simple <a href="../../xmlParser.html">Tutorial</a> to know the basics...
  47. *
  48. * \section usage General usage: How to include the XMLParser library inside your project.
  49. *
  50. * The library is composed of two files: <a href="../../xmlParser.cpp">xmlParser.cpp</a> and
  51. * <a href="../../xmlParser.h">xmlParser.h</a>. These are the ONLY 2 files that you need when
  52. * using the library inside your own projects.
  53. *
  54. * All the functions of the library are documented inside the comments of the file
  55. * <a href="../../xmlParser.h">xmlParser.h</a>. These comments can be transformed in
  56. * full-fledged HTML documentation using the DOXYGEN software: simply type: "doxygen doxy.cfg"
  57. *
  58. * By default, the XMLParser library uses (char*) for string representation.To use the (wchar_t*)
  59. * version of the library, you need to define the "_UNICODE" preprocessor definition variable
  60. * (this is usually done inside your project definition file) (This is done automatically for you
  61. * when using Visual Studio).
  62. *
  63. * \section example Advanced Tutorial and Many Examples of usage.
  64. *
  65. * Some very small introductory examples are described inside the Tutorial file
  66. * <a href="../../xmlParser.html">xmlParser.html</a>
  67. *
  68. * Some additional small examples are also inside the file <a href="../../xmlTest.cpp">xmlTest.cpp</a>
  69. * (for the "char*" version of the library) and inside the file
  70. * <a href="../../xmlTestUnicode.cpp">xmlTestUnicode.cpp</a> (for the "wchar_t*"
  71. * version of the library). If you have a question, please review these additionnal examples
  72. * before sending an e-mail to the author.
  73. *
  74. * To build the examples:
  75. * - linux/unix: type "make"
  76. * - solaris: type "make -f makefile.solaris"
  77. * - windows: Visual Studio: double-click on xmlParser.dsw
  78. * (under Visual Studio .NET, the .dsp and .dsw files will be automatically converted to .vcproj and .sln files)
  79. *
  80. * In order to build the examples you need some additional files:
  81. * - linux/unix: makefile
  82. * - solaris: makefile.solaris
  83. * - windows: Visual Studio: *.dsp, xmlParser.dsw and also xmlParser.lib and xmlParser.dll
  84. *
  85. * \section debugging Debugging with the XMLParser library
  86. *
  87. * \subsection debugwin Debugging under WINDOWS
  88. *
  89. * Inside Visual C++, the "debug versions" of the memory allocation functions are
  90. * very slow: Do not forget to compile in "release mode" to get maximum speed.
  91. * When I have to debug a software that is using the XMLParser Library, it was usually
  92. * a nightmare because the library was sooOOOoooo slow in debug mode (because of the
  93. * slow memory allocations in Debug mode). To solve this
  94. * problem, during all the debugging session, I use a very fast DLL version of the
  95. * XMLParser Library (the DLL is compiled in release mode). Using the DLL version of
  96. * the XMLParser Library allows me to have lightening XML parsing speed even in debug!
  97. * Other than that, the DLL version is useless: In the release version of my tool,
  98. * I always use the normal, ".cpp"-based, XMLParser Library (I simply include the
  99. * <a href="../../xmlParser.cpp">xmlParser.cpp</a> and
  100. * <a href="../../xmlParser.h">xmlParser.h</a> files into the project).
  101. *
  102. * The file <a href="../../XMLNodeAutoexp.txt">XMLNodeAutoexp.txt</a> contains some
  103. * "tweaks" that improve substancially the display of the content of the XMLNode objects
  104. * inside the Visual Studio Debugger. Believe me, once you have seen inside the debugger
  105. * the "smooth" display of the XMLNode objects, you cannot live without it anymore!
  106. *
  107. * \subsection debuglinux Debugging under LINUX/UNIX
  108. *
  109. * The speed of the debug version of the XMLParser library is tolerable so no extra
  110. * work.has been done.
  111. *
  112. ****************************************************************************/
  113. #ifndef __INCLUDE_XML_NODE__
  114. #define __INCLUDE_XML_NODE__
  115. #include <stdlib.h>
  116. #ifdef _UNICODE
  117. // If you comment the next "define" line then the library will never "switch to" _UNICODE (wchar_t*) mode (16/32 bits per characters).
  118. // This is useful when you get error messages like:
  119. // 'XMLNode::openFileHelper' : cannot convert parameter 2 from 'const char [5]' to 'const wchar_t *'
  120. // The _XMLWIDECHAR preprocessor variable force the XMLParser library into either utf16/32-mode (the proprocessor variable
  121. // must be defined) or utf8-mode(the pre-processor variable must be undefined).
  122. #define _XMLWIDECHAR
  123. #endif
  124. #if defined(WIN32) || defined(UNDER_CE) || defined(_WIN32) || defined(WIN64) || defined(__BORLANDC__)
  125. // comment the next line if you are under windows and the compiler is not Microsoft Visual Studio (6.0 or .NET) or Borland
  126. #define _XMLWINDOWS
  127. #endif
  128. #ifdef XMLDLLENTRY
  129. #undef XMLDLLENTRY
  130. #endif
  131. #ifdef _USE_XMLPARSER_DLL
  132. #ifdef _DLL_EXPORTS_
  133. #define XMLDLLENTRY __declspec(dllexport)
  134. #else
  135. #define XMLDLLENTRY __declspec(dllimport)
  136. #endif
  137. #else
  138. #define XMLDLLENTRY
  139. #endif
  140. // uncomment the next line if you want no support for wchar_t* (no need for the <wchar.h> or <tchar.h> libraries anymore to compile)
  141. //#define XML_NO_WIDE_CHAR
  142. #ifdef XML_NO_WIDE_CHAR
  143. #undef _XMLWINDOWS
  144. #undef _XMLWIDECHAR
  145. #endif
  146. #ifdef _XMLWINDOWS
  147. #include <tchar.h>
  148. #else
  149. #define XMLDLLENTRY
  150. #ifndef XML_NO_WIDE_CHAR
  151. #include <wchar.h> // to have 'wcsrtombs' for ANSI version
  152. // to have 'mbsrtowcs' for WIDECHAR version
  153. #endif
  154. #endif
  155. // Some common types for char set portable code
  156. #ifdef _XMLWIDECHAR
  157. #define _CXML(c) L ## c
  158. #define XMLCSTR const wchar_t *
  159. #define XMLSTR wchar_t *
  160. #define XMLCHAR wchar_t
  161. #else
  162. #define _CXML(c) c
  163. #define XMLCSTR const char *
  164. #define XMLSTR char *
  165. #define XMLCHAR char
  166. #endif
  167. #ifndef FALSE
  168. #define FALSE 0
  169. #endif /* FALSE */
  170. #ifndef TRUE
  171. #define TRUE 1
  172. #endif /* TRUE */
  173. /// Enumeration for XML parse errors.
  174. typedef enum XMLError
  175. {
  176. eXMLErrorNone = 0,
  177. eXMLErrorMissingEndTag,
  178. eXMLErrorNoXMLTagFound,
  179. eXMLErrorEmpty,
  180. eXMLErrorMissingTagName,
  181. eXMLErrorMissingEndTagName,
  182. eXMLErrorUnmatchedEndTag,
  183. eXMLErrorUnmatchedEndClearTag,
  184. eXMLErrorUnexpectedToken,
  185. eXMLErrorNoElements,
  186. eXMLErrorFileNotFound,
  187. eXMLErrorFirstTagNotFound,
  188. eXMLErrorUnknownCharacterEntity,
  189. eXMLErrorCharacterCodeAbove255,
  190. eXMLErrorCharConversionError,
  191. eXMLErrorCannotOpenWriteFile,
  192. eXMLErrorCannotWriteFile,
  193. eXMLErrorBase64DataSizeIsNotMultipleOf4,
  194. eXMLErrorBase64DecodeIllegalCharacter,
  195. eXMLErrorBase64DecodeTruncatedData,
  196. eXMLErrorBase64DecodeBufferTooSmall
  197. } XMLError;
  198. /// Enumeration used to manage type of data. Use in conjunction with structure XMLNodeContents
  199. typedef enum XMLElementType
  200. {
  201. eNodeChild=0,
  202. eNodeAttribute=1,
  203. eNodeText=2,
  204. eNodeClear=3,
  205. eNodeNULL=4
  206. } XMLElementType;
  207. /// Structure used to obtain error details if the parse fails.
  208. typedef struct XMLResults
  209. {
  210. enum XMLError error;
  211. int nLine,nColumn;
  212. } XMLResults;
  213. /// Structure for XML clear (unformatted) node (usually comments)
  214. typedef struct XMLClear {
  215. XMLCSTR lpszValue; XMLCSTR lpszOpenTag; XMLCSTR lpszCloseTag;
  216. } XMLClear;
  217. /// Structure for XML attribute.
  218. typedef struct XMLAttribute {
  219. XMLCSTR lpszName; XMLCSTR lpszValue;
  220. } XMLAttribute;
  221. /// XMLElementPosition are not interchangeable with simple indexes
  222. typedef int XMLElementPosition;
  223. struct XMLNodeContents;
  224. /** @defgroup XMLParserGeneral The XML parser */
  225. /// Main Class representing a XML node
  226. /**
  227. * All operations are performed using this class.
  228. * \note The constructors of the XMLNode class are protected, so use instead one of these four methods to get your first instance of XMLNode:
  229. * <ul>
  230. * <li> XMLNode::parseString </li>
  231. * <li> XMLNode::parseFile </li>
  232. * <li> XMLNode::openFileHelper </li>
  233. * <li> XMLNode::createXMLTopNode (or XMLNode::createXMLTopNode_WOSD)</li>
  234. * </ul> */
  235. typedef struct XMLDLLENTRY XMLNode
  236. {
  237. private:
  238. struct XMLNodeDataTag;
  239. /// Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode
  240. XMLNode(struct XMLNodeDataTag *pParent, XMLSTR lpszName, char isDeclaration);
  241. /// Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode
  242. XMLNode(struct XMLNodeDataTag *p);
  243. public:
  244. static XMLCSTR getVersion();///< Return the XMLParser library version number
  245. /** @defgroup conversions Parsing XML files/strings to an XMLNode structure and Rendering XMLNode's to files/string.
  246. * @ingroup XMLParserGeneral
  247. * @{ */
  248. /// Parse an XML string and return the root of a XMLNode tree representing the string.
  249. static XMLNode parseString (XMLCSTR lpXMLString, XMLCSTR tag=NULL, XMLResults *pResults=NULL);
  250. /**< The "parseString" function parse an XML string and return the root of a XMLNode tree. The "opposite" of this function is
  251. * the function "createXMLString" that re-creates an XML string from an XMLNode tree. If the XML document is corrupted, the
  252. * "parseString" method will initialize the "pResults" variable with some information that can be used to trace the error.
  253. * If you still want to parse the file, you can use the APPROXIMATE_PARSING option as explained inside the note at the
  254. * beginning of the "xmlParser.cpp" file.
  255. *
  256. * @param lpXMLString the XML string to parse
  257. * @param tag the name of the first tag inside the XML file. If the tag parameter is omitted, this function returns a node that represents the head of the xml document including the declaration term (<? ... ?>).
  258. * @param pResults a pointer to a XMLResults variable that will contain some information that can be used to trace the XML parsing error. You can have a user-friendly explanation of the parsing error with the "getError" function.
  259. */
  260. /// Parse an XML file and return the root of a XMLNode tree representing the file.
  261. static XMLNode parseFile (XMLCSTR filename, XMLCSTR tag=NULL, XMLResults *pResults=NULL);
  262. /**< The "parseFile" function parse an XML file and return the root of a XMLNode tree. The "opposite" of this function is
  263. * the function "writeToFile" that re-creates an XML file from an XMLNode tree. If the XML document is corrupted, the
  264. * "parseFile" method will initialize the "pResults" variable with some information that can be used to trace the error.
  265. * If you still want to parse the file, you can use the APPROXIMATE_PARSING option as explained inside the note at the
  266. * beginning of the "xmlParser.cpp" file.
  267. *
  268. * @param filename the path to the XML file to parse
  269. * @param tag the name of the first tag inside the XML file. If the tag parameter is omitted, this function returns a node that represents the head of the xml document including the declaration term (<? ... ?>).
  270. * @param pResults a pointer to a XMLResults variable that will contain some information that can be used to trace the XML parsing error. You can have a user-friendly explanation of the parsing error with the "getError" function.
  271. */
  272. /// Parse an XML file and return the root of a XMLNode tree representing the file. A very crude error checking is made. An attempt to guess the Char Encoding used in the file is made.
  273. static XMLNode openFileHelper(XMLCSTR filename, XMLCSTR tag=NULL);
  274. /**< The "openFileHelper" function reports to the screen all the warnings and errors that occurred during parsing of the XML file.
  275. * This function also tries to guess char Encoding (UTF-8, ASCII or SHIT-JIS) based on the first 200 bytes of the file. Since each
  276. * application has its own way to report and deal with errors, you should rather use the "parseFile" function to parse XML files
  277. * and program yourself thereafter an "error reporting" tailored for your needs (instead of using the very crude "error reporting"
  278. * mechanism included inside the "openFileHelper" function).
  279. *
  280. * If the XML document is corrupted, the "openFileHelper" method will:
  281. * - display an error message on the console (or inside a messageBox for windows).
  282. * - stop execution (exit).
  283. *
  284. * I strongly suggest that you write your own "openFileHelper" method tailored to your needs. If you still want to parse
  285. * the file, you can use the APPROXIMATE_PARSING option as explained inside the note at the beginning of the "xmlParser.cpp" file.
  286. *
  287. * @param filename the path of the XML file to parse.
  288. * @param tag the name of the first tag inside the XML file. If the tag parameter is omitted, this function returns a node that represents the head of the xml document including the declaration term (<? ... ?>).
  289. */
  290. static XMLCSTR getError(XMLError error); ///< this gives you a user-friendly explanation of the parsing error
  291. /// Create an XML string starting from the current XMLNode.
  292. XMLSTR createXMLString(int nFormat=1, int *pnSize=NULL) const;
  293. /**< The returned string should be free'd using the "freeXMLString" function.
  294. *
  295. * If nFormat==0, no formatting is required otherwise this returns an user friendly XML string from a given element
  296. * with appropriate white spaces and carriage returns. if pnSize is given it returns the size in character of the string. */
  297. /// Save the content of an xmlNode inside a file
  298. XMLError writeToFile(XMLCSTR filename,
  299. const char *encoding=NULL,
  300. char nFormat=1) const;
  301. /**< If nFormat==0, no formatting is required otherwise this returns an user friendly XML string from a given element with appropriate white spaces and carriage returns.
  302. * If the global parameter "characterEncoding==encoding_UTF8", then the "encoding" parameter is ignored and always set to "utf-8".
  303. * If the global parameter "characterEncoding==encoding_ShiftJIS", then the "encoding" parameter is ignored and always set to "SHIFT-JIS".
  304. * If "_XMLWIDECHAR=1", then the "encoding" parameter is ignored and always set to "utf-16".
  305. * If no "encoding" parameter is given the "ISO-8859-1" encoding is used. */
  306. /** @} */
  307. /** @defgroup navigate Navigate the XMLNode structure
  308. * @ingroup XMLParserGeneral
  309. * @{ */
  310. XMLCSTR getName() const; ///< name of the node
  311. XMLCSTR getText(int i=0) const; ///< return ith text field
  312. int nText() const; ///< nbr of text field
  313. XMLNode getParentNode() const; ///< return the parent node
  314. XMLNode getChildNode(int i=0) const; ///< return ith child node
  315. XMLNode getChildNode(XMLCSTR name, int i) const; ///< return ith child node with specific name (return an empty node if failing). If i==-1, this returns the last XMLNode with the given name.
  316. XMLNode getChildNode(XMLCSTR name, int *i=NULL) const; ///< return next child node with specific name (return an empty node if failing)
  317. XMLNode getChildNodeWithAttribute(XMLCSTR tagName,
  318. XMLCSTR attributeName,
  319. XMLCSTR attributeValue=NULL,
  320. int *i=NULL) const; ///< return child node with specific name/attribute (return an empty node if failing)
  321. XMLNode getChildNodeByPath(XMLCSTR path, char createNodeIfMissing=0, XMLCHAR sep='/');
  322. ///< return the first child node with specific path
  323. XMLNode getChildNodeByPathNonConst(XMLSTR path, char createNodeIfMissing=0, XMLCHAR sep='/');
  324. ///< return the first child node with specific path.
  325. int nChildNode(XMLCSTR name) const; ///< return the number of child node with specific name
  326. int nChildNode() const; ///< nbr of child node
  327. XMLAttribute getAttribute(int i=0) const; ///< return ith attribute
  328. XMLCSTR getAttributeName(int i=0) const; ///< return ith attribute name
  329. XMLCSTR getAttributeValue(int i=0) const; ///< return ith attribute value
  330. char isAttributeSet(XMLCSTR name) const; ///< test if an attribute with a specific name is given
  331. XMLCSTR getAttribute(XMLCSTR name, int i) const; ///< return ith attribute content with specific name (return a NULL if failing)
  332. XMLCSTR getAttribute(XMLCSTR name, int *i=NULL) const; ///< return next attribute content with specific name (return a NULL if failing)
  333. int nAttribute() const; ///< nbr of attribute
  334. XMLClear getClear(int i=0) const; ///< return ith clear field (comments)
  335. int nClear() const; ///< nbr of clear field
  336. XMLNodeContents enumContents(XMLElementPosition i) const; ///< enumerate all the different contents (attribute,child,text, clear) of the current XMLNode. The order is reflecting the order of the original file/string. NOTE: 0 <= i < nElement();
  337. int nElement() const; ///< nbr of different contents for current node
  338. char isEmpty() const; ///< is this node Empty?
  339. char isDeclaration() const; ///< is this node a declaration <? .... ?>
  340. XMLNode deepCopy() const; ///< deep copy (duplicate/clone) a XMLNode
  341. static XMLNode emptyNode(); ///< return XMLNode::emptyXMLNode;
  342. /** @} */
  343. ~XMLNode();
  344. XMLNode(const XMLNode &A); ///< to allow shallow/fast copy:
  345. XMLNode& operator=( const XMLNode& A ); ///< to allow shallow/fast copy:
  346. XMLNode(): d(NULL){};
  347. static XMLNode emptyXMLNode;
  348. static XMLClear emptyXMLClear;
  349. static XMLAttribute emptyXMLAttribute;
  350. /** @defgroup xmlModify Create or Update the XMLNode structure
  351. * @ingroup XMLParserGeneral
  352. * The functions in this group allows you to create from scratch (or update) a XMLNode structure. Start by creating your top
  353. * node with the "createXMLTopNode" function and then add new nodes with the "addChild" function. The parameter 'pos' gives
  354. * the position where the childNode, the text or the XMLClearTag will be inserted. The default value (pos=-1) inserts at the
  355. * end. The value (pos=0) insert at the beginning (Insertion at the beginning is slower than at the end). <br>
  356. *
  357. * REMARK: 0 <= pos < nChild()+nText()+nClear() <br>
  358. */
  359. /** @defgroup creation Creating from scratch a XMLNode structure
  360. * @ingroup xmlModify
  361. * @{ */
  362. static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE); ///< Create the top node of an XMLNode structure
  363. XMLNode addChild(XMLCSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1); ///< Add a new child node
  364. XMLNode addChild(XMLNode nodeToAdd, XMLElementPosition pos=-1); ///< If the "nodeToAdd" has some parents, it will be detached from it's parents before being attached to the current XMLNode
  365. XMLAttribute *addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev); ///< Add a new attribute
  366. XMLCSTR addText(XMLCSTR lpszValue, XMLElementPosition pos=-1); ///< Add a new text content
  367. XMLClear *addClear(XMLCSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, XMLElementPosition pos=-1);
  368. /**< Add a new clear tag
  369. * @param lpszOpen default value "<![CDATA["
  370. * @param lpszClose default value "]]>"
  371. */
  372. /** @} */
  373. /** @defgroup xmlUpdate Updating Nodes
  374. * @ingroup xmlModify
  375. * Some update functions:
  376. * @{
  377. */
  378. XMLCSTR updateName(XMLCSTR lpszName); ///< change node's name
  379. XMLAttribute *updateAttribute(XMLAttribute *newAttribute, XMLAttribute *oldAttribute); ///< if the attribute to update is missing, a new one will be added
  380. XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName=NULL,int i=0); ///< if the attribute to update is missing, a new one will be added
  381. XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,XMLCSTR lpszOldName);///< set lpszNewName=NULL if you don't want to change the name of the attribute if the attribute to update is missing, a new one will be added
  382. XMLCSTR updateText(XMLCSTR lpszNewValue, int i=0); ///< if the text to update is missing, a new one will be added
  383. XMLCSTR updateText(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the text to update is missing, a new one will be added
  384. XMLClear *updateClear(XMLCSTR lpszNewContent, int i=0); ///< if the clearTag to update is missing, a new one will be added
  385. XMLClear *updateClear(XMLClear *newP,XMLClear *oldP); ///< if the clearTag to update is missing, a new one will be added
  386. XMLClear *updateClear(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the clearTag to update is missing, a new one will be added
  387. /** @} */
  388. /** @defgroup xmlDelete Deleting Nodes or Attributes
  389. * @ingroup xmlModify
  390. * Some deletion functions:
  391. * @{
  392. */
  393. /// The "deleteNodeContent" function forces the deletion of the content of this XMLNode and the subtree.
  394. void deleteNodeContent();
  395. /**< \note The XMLNode instances that are referring to the part of the subtree that has been deleted CANNOT be used anymore!!. Unexpected results will occur if you continue using them. */
  396. void deleteAttribute(int i=0); ///< Delete the ith attribute of the current XMLNode
  397. void deleteAttribute(XMLCSTR lpszName); ///< Delete the attribute with the given name (the "strcmp" function is used to find the right attribute)
  398. void deleteAttribute(XMLAttribute *anAttribute); ///< Delete the attribute with the name "anAttribute->lpszName" (the "strcmp" function is used to find the right attribute)
  399. void deleteText(int i=0); ///< Delete the Ith text content of the current XMLNode
  400. void deleteText(XMLCSTR lpszValue); ///< Delete the text content "lpszValue" inside the current XMLNode (direct "pointer-to-pointer" comparison is used to find the right text)
  401. void deleteClear(int i=0); ///< Delete the Ith clear tag inside the current XMLNode
  402. void deleteClear(XMLCSTR lpszValue); ///< Delete the clear tag "lpszValue" inside the current XMLNode (direct "pointer-to-pointer" comparison is used to find the clear tag)
  403. void deleteClear(XMLClear *p); ///< Delete the clear tag "p" inside the current XMLNode (direct "pointer-to-pointer" comparison on the lpszName of the clear tag is used to find the clear tag)
  404. /** @} */
  405. /** @defgroup xmlWOSD ???_WOSD functions.
  406. * @ingroup xmlModify
  407. * The strings given as parameters for the "add" and "update" methods that have a name with
  408. * the postfix "_WOSD" (that means "WithOut String Duplication")(for example "addText_WOSD")
  409. * will be free'd by the XMLNode class. For example, it means that this is incorrect:
  410. * \code
  411. * xNode.addText_WOSD("foo");
  412. * xNode.updateAttribute_WOSD("#newcolor" ,NULL,"color");
  413. * \endcode
  414. * In opposition, this is correct:
  415. * \code
  416. * xNode.addText("foo");
  417. * xNode.addText_WOSD(stringDup("foo"));
  418. * xNode.updateAttribute("#newcolor" ,NULL,"color");
  419. * xNode.updateAttribute_WOSD(stringDup("#newcolor"),NULL,"color");
  420. * \endcode
  421. * Typically, you will never do:
  422. * \code
  423. * char *b=(char*)malloc(...);
  424. * xNode.addText(b);
  425. * free(b);
  426. * \endcode
  427. * ... but rather:
  428. * \code
  429. * char *b=(char*)malloc(...);
  430. * xNode.addText_WOSD(b);
  431. * \endcode
  432. * ('free(b)' is performed by the XMLNode class)
  433. * @{ */
  434. static XMLNode createXMLTopNode_WOSD(XMLSTR lpszName, char isDeclaration=FALSE); ///< Create the top node of an XMLNode structure
  435. XMLNode addChild_WOSD(XMLSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1); ///< Add a new child node
  436. XMLAttribute *addAttribute_WOSD(XMLSTR lpszName, XMLSTR lpszValue); ///< Add a new attribute
  437. XMLCSTR addText_WOSD(XMLSTR lpszValue, XMLElementPosition pos=-1); ///< Add a new text content
  438. XMLClear *addClear_WOSD(XMLSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, XMLElementPosition pos=-1); ///< Add a new clear Tag
  439. XMLCSTR updateName_WOSD(XMLSTR lpszName); ///< change node's name
  440. XMLAttribute *updateAttribute_WOSD(XMLAttribute *newAttribute, XMLAttribute *oldAttribute); ///< if the attribute to update is missing, a new one will be added
  441. XMLAttribute *updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName=NULL,int i=0); ///< if the attribute to update is missing, a new one will be added
  442. XMLAttribute *updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName,XMLCSTR lpszOldName); ///< set lpszNewName=NULL if you don't want to change the name of the attribute if the attribute to update is missing, a new one will be added
  443. XMLCSTR updateText_WOSD(XMLSTR lpszNewValue, int i=0); ///< if the text to update is missing, a new one will be added
  444. XMLCSTR updateText_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the text to update is missing, a new one will be added
  445. XMLClear *updateClear_WOSD(XMLSTR lpszNewContent, int i=0); ///< if the clearTag to update is missing, a new one will be added
  446. XMLClear *updateClear_WOSD(XMLClear *newP,XMLClear *oldP); ///< if the clearTag to update is missing, a new one will be added
  447. XMLClear *updateClear_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the clearTag to update is missing, a new one will be added
  448. /** @} */
  449. /** @defgroup xmlPosition Position helper functions (use in conjunction with the update&add functions
  450. * @ingroup xmlModify
  451. * These are some useful functions when you want to insert a childNode, a text or a XMLClearTag in the
  452. * middle (at a specified position) of a XMLNode tree already constructed. The value returned by these
  453. * methods is to be used as last parameter (parameter 'pos') of addChild, addText or addClear.
  454. * @{ */
  455. XMLElementPosition positionOfText(int i=0) const;
  456. XMLElementPosition positionOfText(XMLCSTR lpszValue) const;
  457. XMLElementPosition positionOfClear(int i=0) const;
  458. XMLElementPosition positionOfClear(XMLCSTR lpszValue) const;
  459. XMLElementPosition positionOfClear(XMLClear *a) const;
  460. XMLElementPosition positionOfChildNode(int i=0) const;
  461. XMLElementPosition positionOfChildNode(XMLNode x) const;
  462. XMLElementPosition positionOfChildNode(XMLCSTR name, int i=0) const; ///< return the position of the ith childNode with the specified name if (name==NULL) return the position of the ith childNode
  463. /** @} */
  464. /// Enumeration for XML character encoding.
  465. typedef enum XMLCharEncoding
  466. {
  467. char_encoding_error=0,
  468. char_encoding_UTF8=1,
  469. char_encoding_legacy=2,
  470. char_encoding_ShiftJIS=3,
  471. char_encoding_GB2312=4,
  472. char_encoding_Big5=5,
  473. char_encoding_GBK=6 // this is actually the same as Big5
  474. } XMLCharEncoding;
  475. /** \addtogroup conversions
  476. * @{ */
  477. /// Sets the global options for the conversions
  478. static char setGlobalOptions(XMLCharEncoding characterEncoding=XMLNode::char_encoding_UTF8, char guessWideCharChars=1,
  479. char dropWhiteSpace=1, char removeCommentsInMiddleOfText=1);
  480. /**< The "setGlobalOptions" function allows you to change four global parameters that affect string & file
  481. * parsing. First of all, you most-probably will never have to change these 3 global parameters.
  482. *
  483. * @param guessWideCharChars If "guessWideCharChars"=1 and if this library is compiled in WideChar mode, then the
  484. * XMLNode::parseFile and XMLNode::openFileHelper functions will test if the file contains ASCII
  485. * characters. If this is the case, then the file will be loaded and converted in memory to
  486. * WideChar before being parsed. If 0, no conversion will be performed.
  487. *
  488. * @param guessWideCharChars If "guessWideCharChars"=1 and if this library is compiled in ASCII/UTF8/char* mode, then the
  489. * XMLNode::parseFile and XMLNode::openFileHelper functions will test if the file contains WideChar
  490. * characters. If this is the case, then the file will be loaded and converted in memory to
  491. * ASCII/UTF8/char* before being parsed. If 0, no conversion will be performed.
  492. *
  493. * @param characterEncoding This parameter is only meaningful when compiling in char* mode (multibyte character mode).
  494. * In wchar_t* (wide char mode), this parameter is ignored. This parameter should be one of the
  495. * three currently recognized encodings: XMLNode::encoding_UTF8, XMLNode::encoding_ascii,
  496. * XMLNode::encoding_ShiftJIS.
  497. *
  498. * @param dropWhiteSpace In most situations, text fields containing only white spaces (and carriage returns)
  499. * are useless. Even more, these "empty" text fields are annoying because they increase the
  500. * complexity of the user's code for parsing. So, 99% of the time, it's better to drop
  501. * the "empty" text fields. However The XML specification indicates that no white spaces
  502. * should be lost when parsing the file. So to be perfectly XML-compliant, you should set
  503. * dropWhiteSpace=0. A note of caution: if you set "dropWhiteSpace=0", the parser will be
  504. * slower and your code will be more complex.
  505. *
  506. * @param removeCommentsInMiddleOfText To explain this parameter, let's consider this code:
  507. * \code
  508. * XMLNode x=XMLNode::parseString("<a>foo<!-- hello -->bar<!DOCTYPE world >chu</a>","a");
  509. * \endcode
  510. * If removeCommentsInMiddleOfText=0, then we will have:
  511. * \code
  512. * x.getText(0) -> "foo"
  513. * x.getText(1) -> "bar"
  514. * x.getText(2) -> "chu"
  515. * x.getClear(0) --> "<!-- hello -->"
  516. * x.getClear(1) --> "<!DOCTYPE world >"
  517. * \endcode
  518. * If removeCommentsInMiddleOfText=1, then we will have:
  519. * \code
  520. * x.getText(0) -> "foobar"
  521. * x.getText(1) -> "chu"
  522. * x.getClear(0) --> "<!DOCTYPE world >"
  523. * \endcode
  524. *
  525. * \return "0" when there are no errors. If you try to set an unrecognized encoding then the return value will be "1" to signal an error.
  526. *
  527. * \note Sometime, it's useful to set "guessWideCharChars=0" to disable any conversion
  528. * because the test to detect the file-type (ASCII/UTF8/char* or WideChar) may fail (rarely). */
  529. /// Guess the character encoding of the string (ascii, utf8 or shift-JIS)
  530. static XMLCharEncoding guessCharEncoding(void *buffer, int bufLen, char useXMLEncodingAttribute=1);
  531. /**< The "guessCharEncoding" function try to guess the character encoding. You most-probably will never
  532. * have to use this function. It then returns the appropriate value of the global parameter
  533. * "characterEncoding" described in the XMLNode::setGlobalOptions. The guess is based on the content of a buffer of length
  534. * "bufLen" bytes that contains the first bytes (minimum 25 bytes; 200 bytes is a good value) of the
  535. * file to be parsed. The XMLNode::openFileHelper function is using this function to automatically compute
  536. * the value of the "characterEncoding" global parameter. There are several heuristics used to do the
  537. * guess. One of the heuristic is based on the "encoding" attribute. The original XML specifications
  538. * forbids to use this attribute to do the guess but you can still use it if you set
  539. * "useXMLEncodingAttribute" to 1 (this is the default behavior and the behavior of most parsers).
  540. * If an inconsistency in the encoding is detected, then the return value is "0". */
  541. /** @} */
  542. private:
  543. // these are functions and structures used internally by the XMLNode class (don't bother about them):
  544. typedef struct XMLNodeDataTag // to allow shallow copy and "intelligent/smart" pointers (automatic delete):
  545. {
  546. XMLCSTR lpszName; // Element name (=NULL if root)
  547. int nChild, // Number of child nodes
  548. nText, // Number of text fields
  549. nClear, // Number of Clear fields (comments)
  550. nAttribute; // Number of attributes
  551. char isDeclaration; // Whether node is an XML declaration - '<?xml ?>'
  552. struct XMLNodeDataTag *pParent; // Pointer to parent element (=NULL if root)
  553. XMLNode *pChild; // Array of child nodes
  554. XMLCSTR *pText; // Array of text fields
  555. XMLClear *pClear; // Array of clear fields
  556. XMLAttribute *pAttribute; // Array of attributes
  557. int *pOrder; // order of the child_nodes,text_fields,clear_fields
  558. int ref_count; // for garbage collection (smart pointers)
  559. } XMLNodeData;
  560. XMLNodeData *d;
  561. char parseClearTag(void *px, void *pa);
  562. char maybeAddTxT(void *pa, XMLCSTR tokenPStr);
  563. int ParseXMLElement(void *pXML);
  564. void *addToOrder(int memInc, int *_pos, int nc, void *p, int size, XMLElementType xtype);
  565. int indexText(XMLCSTR lpszValue) const;
  566. int indexClear(XMLCSTR lpszValue) const;
  567. XMLNode addChild_priv(int,XMLSTR,char,int);
  568. XMLAttribute *addAttribute_priv(int,XMLSTR,XMLSTR);
  569. XMLCSTR addText_priv(int,XMLSTR,int);
  570. XMLClear *addClear_priv(int,XMLSTR,XMLCSTR,XMLCSTR,int);
  571. void emptyTheNode(char force);
  572. static inline XMLElementPosition findPosition(XMLNodeData *d, int index, XMLElementType xtype);
  573. static int CreateXMLStringR(XMLNodeData *pEntry, XMLSTR lpszMarker, int nFormat);
  574. static int removeOrderElement(XMLNodeData *d, XMLElementType t, int index);
  575. static void exactMemory(XMLNodeData *d);
  576. static int detachFromParent(XMLNodeData *d);
  577. } XMLNode;
  578. /// This structure is given by the function XMLNode::enumContents.
  579. typedef struct XMLNodeContents
  580. {
  581. /// This dictates what's the content of the XMLNodeContent
  582. enum XMLElementType etype;
  583. /**< should be an union to access the appropriate data. Compiler does not allow union of object with constructor... too bad. */
  584. XMLNode child;
  585. XMLAttribute attrib;
  586. XMLCSTR text;
  587. XMLClear clear;
  588. } XMLNodeContents;
  589. /** @defgroup StringAlloc String Allocation/Free functions
  590. * @ingroup xmlModify
  591. * @{ */
  592. /// Duplicate (copy in a new allocated buffer) the source string.
  593. XMLDLLENTRY XMLSTR stringDup(XMLCSTR source, int cbData=-1);
  594. /**< This is
  595. * a very handy function when used with all the "XMLNode::*_WOSD" functions (\link xmlWOSD \endlink).
  596. * @param cbData If !=0 then cbData is the number of chars to duplicate. New strings allocated with
  597. * this function should be free'd using the "freeXMLString" function. */
  598. /// to free the string allocated inside the "stringDup" function or the "createXMLString" function.
  599. XMLDLLENTRY void freeXMLString(XMLSTR t); // {free(t);}
  600. /** @} */
  601. /** @defgroup atoX ato? like functions
  602. * @ingroup XMLParserGeneral
  603. * The "xmlto?" functions are equivalents to the atoi, atol, atof functions.
  604. * The only difference is: If the variable "xmlString" is NULL, than the return value
  605. * is "defautValue". These 6 functions are only here as "convenience" functions for the
  606. * user (they are not used inside the XMLparser). If you don't need them, you can
  607. * delete them without any trouble.
  608. *
  609. * @{ */
  610. XMLDLLENTRY char xmltob(XMLCSTR xmlString,char defautValue=0);
  611. XMLDLLENTRY int xmltoi(XMLCSTR xmlString,int defautValue=0);
  612. XMLDLLENTRY long xmltol(XMLCSTR xmlString,long defautValue=0);
  613. XMLDLLENTRY double xmltof(XMLCSTR xmlString,double defautValue=.0);
  614. XMLDLLENTRY XMLCSTR xmltoa(XMLCSTR xmlString,XMLCSTR defautValue=_CXML(""));
  615. XMLDLLENTRY XMLCHAR xmltoc(XMLCSTR xmlString,XMLCHAR defautValue=_CXML('\0'));
  616. /** @} */
  617. /** @defgroup ToXMLStringTool Helper class to create XML files using "printf", "fprintf", "cout",... functions.
  618. * @ingroup XMLParserGeneral
  619. * @{ */
  620. /// Helper class to create XML files using "printf", "fprintf", "cout",... functions.
  621. /** The ToXMLStringTool class helps you creating XML files using "printf", "fprintf", "cout",... functions.
  622. * The "ToXMLStringTool" class is processing strings so that all the characters
  623. * &,",',<,> are replaced by their XML equivalent:
  624. * \verbatim &amp;, &quot;, &apos;, &lt;, &gt; \endverbatim
  625. * Using the "ToXMLStringTool class" and the "fprintf function" is THE most efficient
  626. * way to produce VERY large XML documents VERY fast.
  627. * \note If you are creating from scratch an XML file using the provided XMLNode class
  628. * you must not use the "ToXMLStringTool" class (because the "XMLNode" class does the
  629. * processing job for you during rendering).*/
  630. typedef struct XMLDLLENTRY ToXMLStringTool
  631. {
  632. public:
  633. ToXMLStringTool(): buf(NULL),buflen(0){}
  634. ~ToXMLStringTool();
  635. void freeBuffer();///<call this function when you have finished using this object to release memory used by the internal buffer.
  636. XMLSTR toXML(XMLCSTR source);///< returns a pointer to an internal buffer that contains a XML-encoded string based on the "source" parameter.
  637. /** The "toXMLUnSafe" function is deprecated because there is a possibility of
  638. * "destination-buffer-overflow". It converts the string
  639. * "source" to the string "dest". */
  640. static XMLSTR toXMLUnSafe(XMLSTR dest,XMLCSTR source); ///< deprecated: use "toXML" instead
  641. static int lengthXMLString(XMLCSTR source); ///< deprecated: use "toXML" instead
  642. private:
  643. XMLSTR buf;
  644. int buflen;
  645. } ToXMLStringTool;
  646. /** @} */
  647. /** @defgroup XMLParserBase64Tool Helper class to include binary data inside XML strings using "Base64 encoding".
  648. * @ingroup XMLParserGeneral
  649. * @{ */
  650. /// Helper class to include binary data inside XML strings using "Base64 encoding".
  651. /** The "XMLParserBase64Tool" class allows you to include any binary data (images, sounds,...)
  652. * into an XML document using "Base64 encoding". This class is completely
  653. * separated from the rest of the xmlParser library and can be removed without any problem.
  654. * To include some binary data into an XML file, you must convert the binary data into
  655. * standard text (using "encode"). To retrieve the original binary data from the
  656. * b64-encoded text included inside the XML file, use "decode". Alternatively, these
  657. * functions can also be used to "encrypt/decrypt" some critical data contained inside
  658. * the XML (it's not a strong encryption at all, but sometimes it can be useful). */
  659. typedef struct XMLDLLENTRY XMLParserBase64Tool
  660. {
  661. public:
  662. XMLParserBase64Tool(): buf(NULL),buflen(0){}
  663. ~XMLParserBase64Tool();
  664. void freeBuffer();///< Call this function when you have finished using this object to release memory used by the internal buffer.
  665. /**
  666. * @param formatted If "formatted"=true, some space will be reserved for a carriage-return every 72 chars. */
  667. static int encodeLength(int inBufLen, char formatted=0); ///< return the length of the base64 string that encodes a data buffer of size inBufLen bytes.
  668. /**
  669. * The "base64Encode" function returns a string containing the base64 encoding of "inByteLen" bytes
  670. * from "inByteBuf". If "formatted" parameter is true, then there will be a carriage-return every 72 chars.
  671. * The string will be free'd when the XMLParserBase64Tool object is deleted.
  672. * All returned strings are sharing the same memory space. */
  673. XMLSTR encode(unsigned char *inByteBuf, unsigned int inByteLen, char formatted=0); ///< returns a pointer to an internal buffer containing the base64 string containing the binary data encoded from "inByteBuf"
  674. /// returns the number of bytes which will be decoded from "inString".
  675. static unsigned int decodeSize(XMLCSTR inString, XMLError *xe=NULL);
  676. /**
  677. * The "decode" function returns a pointer to a buffer containing the binary data decoded from "inString"
  678. * The output buffer will be free'd when the XMLParserBase64Tool object is deleted.
  679. * All output buffer are sharing the same memory space.
  680. * @param inString If "instring" is malformed, NULL will be returned */
  681. unsigned char* decode(XMLCSTR inString, int *outByteLen=NULL, XMLError *xe=NULL); ///< returns a pointer to an internal buffer containing the binary data decoded from "inString"
  682. /**
  683. * decodes data from "inString" to "outByteBuf". You need to provide the size (in byte) of "outByteBuf"
  684. * in "inMaxByteOutBuflen". If "outByteBuf" is not large enough or if data is malformed, then "FALSE"
  685. * will be returned; otherwise "TRUE". */
  686. static unsigned char decode(XMLCSTR inString, unsigned char *outByteBuf, int inMaxByteOutBuflen, XMLError *xe=NULL); ///< deprecated.
  687. private:
  688. void *buf;
  689. int buflen;
  690. void alloc(int newsize);
  691. }XMLParserBase64Tool;
  692. /** @} */
  693. #undef XMLDLLENTRY
  694. #endif