irrXML.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine" and the "irrXML" project.
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
  4. #ifndef IRR_XML_H_INCLUDED
  5. #define IRR_XML_H_INCLUDED
  6. #include <stdio.h>
  7. #include "IrrCompileConfig.h"
  8. #include "irrArray.h"
  9. #include "irrString.h"
  10. /** \mainpage irrXML 1.2 API documentation
  11. <div align="center"><img src="logobig.png" ></div>
  12. \section intro Introduction
  13. Welcome to the irrXML API documentation.
  14. Here you'll find any information you'll need to develop applications with
  15. irrXML. If you look for a tutorial on how to start, take a look at the \ref irrxmlexample,
  16. at the homepage of irrXML at <A HREF="http://www.ambiera.com/irrxml/">www.ambiera.com/irrxml/</A>
  17. or into the SDK in the directory example.
  18. irrXML is intended to be a high speed and easy-to-use XML Parser for C++, and
  19. this documentation is an important part of it. If you have any questions or
  20. suggestions, just send a email to the author of the engine, Nikolaus Gebhardt
  21. (niko (at) irrlicht3d.org). For more information about this parser, see \ref history.
  22. \section features Features
  23. irrXML provides forward-only, read-only
  24. access to a stream of non validated XML data. It was fully implemented by
  25. Nikolaus Gebhardt. Its current features are:
  26. - It it fast as lighting and has very low memory usage. It was
  27. developed with the intention of being used in 3D games, as it already has been.
  28. - irrXML is very small: It only consists of 60 KB of code and can be added easily
  29. to your existing project.
  30. - Of course, it is platform independent and works with lots of compilers.
  31. - It is able to parse ASCII, UTF-8, UTF-16 and UTF-32 text files, both in
  32. little and big endian format.
  33. - Independent of the input file format, the parser can return all strings in ASCII, UTF-8,
  34. UTF-16 and UTF-32 format.
  35. - With its optional file access abstraction it has the advantage that it can read not
  36. only from files but from any type of data (memory, network, ...). For example when
  37. used with the Irrlicht Engine, it directly reads from compressed .zip files.
  38. - Just like the Irrlicht Engine for which it was originally created, it is extremely easy
  39. to use.
  40. - It has no external dependencies, it does not even need the STL.
  41. Although irrXML has some strengths, it currently also has the following limitations:
  42. - The input xml file is not validated and assumed to be correct.
  43. \section irrxmlexample Example
  44. The following code demonstrates the basic usage of irrXML. A simple xml
  45. file like this is parsed:
  46. \code
  47. <?xml version="1.0"?>
  48. <config>
  49. <!-- This is a config file for the mesh viewer -->
  50. <model file="dwarf.dea" />
  51. <messageText caption="Irrlicht Engine Mesh Viewer">
  52. Welcome to the Mesh Viewer of the &quot;Irrlicht Engine&quot;.
  53. </messageText>
  54. </config>
  55. \endcode
  56. The code for parsing this file would look like this:
  57. \code
  58. #include <irrXML.h>
  59. using namespace irr; // irrXML is located in the namespace irr::io
  60. using namespace io;
  61. #include <string> // we use STL strings to store data in this example
  62. void main()
  63. {
  64. // create the reader using one of the factory functions
  65. IrrXMLReader* xml = createIrrXMLReader("config.xml");
  66. // strings for storing the data we want to get out of the file
  67. std::string modelFile;
  68. std::string messageText;
  69. std::string caption;
  70. // parse the file until end reached
  71. while(xml && xml->read())
  72. {
  73. switch(xml->getNodeType())
  74. {
  75. case EXN_TEXT:
  76. // in this xml file, the only text which occurs is the messageText
  77. messageText = xml->getNodeData();
  78. break;
  79. case EXN_ELEMENT:
  80. {
  81. if (!strcmp("model", xml->getNodeName()))
  82. modelFile = xml->getAttributeValue("file");
  83. else
  84. if (!strcmp("messageText", xml->getNodeName()))
  85. caption = xml->getAttributeValue("caption");
  86. }
  87. break;
  88. }
  89. }
  90. // delete the xml parser after usage
  91. delete xml;
  92. }
  93. \endcode
  94. \section howto How to use
  95. Simply add the source files in the /src directory of irrXML to your project. Done.
  96. \section license License
  97. The irrXML license is based on the zlib license. Basically, this means you can do with
  98. irrXML whatever you want:
  99. Copyright (C) 2002-2012 Nikolaus Gebhardt
  100. This software is provided 'as-is', without any express or implied
  101. warranty. In no event will the authors be held liable for any damages
  102. arising from the use of this software.
  103. Permission is granted to anyone to use this software for any purpose,
  104. including commercial applications, and to alter it and redistribute it
  105. freely, subject to the following restrictions:
  106. 1. The origin of this software must not be misrepresented; you must not
  107. claim that you wrote the original software. If you use this software
  108. in a product, an acknowledgment in the product documentation would be
  109. appreciated but is not required.
  110. 2. Altered source versions must be plainly marked as such, and must not be
  111. misrepresented as being the original software.
  112. 3. This notice may not be removed or altered from any source distribution.
  113. \section history History
  114. As lots of references in this documentation and the source show, this xml
  115. parser has originally been a part of the
  116. <A HREF="http://irrlicht.sourceforge.net" >Irrlicht Engine</A>. But because
  117. the parser has become very useful with the latest release, people asked for a
  118. separate version of it, to be able to use it in non Irrlicht projects. With
  119. irrXML 1.0, this has now been done.
  120. */
  121. namespace irr
  122. {
  123. namespace io
  124. {
  125. //! Enumeration of all supported source text file formats
  126. enum ETEXT_FORMAT
  127. {
  128. //! ASCII, file without byte order mark, or not a text file
  129. ETF_ASCII,
  130. //! UTF-8 format
  131. ETF_UTF8,
  132. //! UTF-16 format, big endian
  133. ETF_UTF16_BE,
  134. //! UTF-16 format, little endian
  135. ETF_UTF16_LE,
  136. //! UTF-32 format, big endian
  137. ETF_UTF32_BE,
  138. //! UTF-32 format, little endian
  139. ETF_UTF32_LE
  140. };
  141. //! Enumeration for all xml nodes which are parsed by IrrXMLReader
  142. enum EXML_NODE
  143. {
  144. //! No xml node. This is usually the node if you did not read anything yet.
  145. EXN_NONE,
  146. //! An xml element such as &lt;foo&gt;
  147. EXN_ELEMENT,
  148. //! End of an xml element such as &lt;/foo&gt;
  149. EXN_ELEMENT_END,
  150. //! Text within an xml element: &lt;foo&gt; this is the text. &lt;/foo&gt;
  151. //! Also text between 2 xml elements: &lt;/foo&gt; this is the text. &lt;foo&gt;
  152. EXN_TEXT,
  153. //! An xml comment like &lt;!-- I am a comment --&gt; or a DTD definition.
  154. EXN_COMMENT,
  155. //! An xml cdata section like &lt;![CDATA[ this is some CDATA ]]&gt;
  156. EXN_CDATA,
  157. //! Unknown element. Also xml headers nodes (which currently also don't read attributes)
  158. EXN_UNKNOWN
  159. };
  160. //! Callback class for file read abstraction.
  161. /** With this, it is possible to make the xml parser read in other
  162. things than just files. The Irrlicht engine is using this for example to
  163. read xml from compressed .zip files. To make the parser read in
  164. any other data, derive a class from this interface, implement the
  165. two methods to read your data and give a pointer to an instance of
  166. your implementation when calling createIrrXMLReader(),
  167. createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */
  168. class IFileReadCallBack
  169. {
  170. public:
  171. //! Destructor
  172. virtual ~IFileReadCallBack() {}
  173. //! Reads an amount of bytes from the file.
  174. /** \param buffer: Pointer to buffer where to read bytes will be written to.
  175. \param sizeToRead: Amount of bytes to read from the file.
  176. \return Returns how much bytes were read. */
  177. virtual int read(void* buffer, int sizeToRead) = 0;
  178. //! Returns size of file in bytes on success or -1L on failure.
  179. virtual long getSize() const = 0;
  180. };
  181. //! Empty class to be used as parent class for IrrXMLReader.
  182. /** If you need another class as base class for the xml reader, you can do this by creating
  183. the reader using for example new CXMLReaderImpl<char, YourBaseClass>(yourcallback);
  184. The Irrlicht Engine for example needs IReferenceCounted as base class for every object to
  185. let it automatically reference counted, hence it replaces IXMLBase with IReferenceCounted.
  186. See irrXML.cpp on how this can be done in detail. */
  187. class IXMLBase
  188. {
  189. };
  190. //! Interface providing easy read access to a XML file.
  191. /** You can create an instance of this reader using one of the factory functions
  192. createIrrXMLReader(), createIrrXMLReaderUTF16() and createIrrXMLReaderUTF32().
  193. If using the parser from the Irrlicht Engine, please use IFileSystem::createXMLReader()
  194. instead.
  195. For a detailed intro how to use the parser, see \ref irrxmlexample and \ref features.
  196. The typical usage of this parser looks like this:
  197. \code
  198. #include <irrXML.h>
  199. using namespace irr; // irrXML is located in the namespace irr::io
  200. using namespace io;
  201. void main()
  202. {
  203. // create the reader using one of the factory functions
  204. IrrXMLReader* xml = createIrrXMLReader("config.xml");
  205. if (xml == 0)
  206. return; // file could not be opened
  207. // parse the file until end reached
  208. while(xml->read())
  209. {
  210. // based on xml->getNodeType(), do something.
  211. }
  212. // delete the xml parser after usage
  213. delete xml;
  214. }
  215. \endcode
  216. See \ref irrxmlexample for a more detailed example.
  217. */
  218. template<class char_type, class super_class>
  219. class IIrrXMLReader : public super_class
  220. {
  221. public:
  222. //! Destructor
  223. virtual ~IIrrXMLReader() {}
  224. //! Reads forward to the next xml node.
  225. /** \return Returns false, if there was no further node. */
  226. virtual bool read() = 0;
  227. //! Returns the type of the current XML node.
  228. virtual EXML_NODE getNodeType() const = 0;
  229. //! Returns attribute count of the current XML node.
  230. /** This is usually
  231. non null if the current node is EXN_ELEMENT, and the element has attributes.
  232. \return Returns amount of attributes of this xml node. */
  233. virtual unsigned int getAttributeCount() const = 0;
  234. //! Returns name of an attribute.
  235. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
  236. \return Name of the attribute, 0 if an attribute with this index does not exist. */
  237. virtual const char_type* getAttributeName(int idx) const = 0;
  238. //! Returns the value of an attribute.
  239. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
  240. \return Value of the attribute, 0 if an attribute with this index does not exist. */
  241. virtual const char_type* getAttributeValue(int idx) const = 0;
  242. //! Returns the value of an attribute.
  243. /** \param name: Name of the attribute.
  244. \return Value of the attribute, 0 if an attribute with this name does not exist. */
  245. virtual const char_type* getAttributeValue(const char_type* name) const = 0;
  246. //! Returns the value of an attribute in a safe way.
  247. /** Like getAttributeValue(), but does not
  248. return 0 if the attribute does not exist. An empty string ("") is returned then.
  249. \param name: Name of the attribute.
  250. \return Value of the attribute, and "" if an attribute with this name does not exist */
  251. virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0;
  252. //! Returns the value of an attribute as integer.
  253. /** \param name Name of the attribute.
  254. \param defaultNotFound Value returned when name does not exist
  255. \return Value of the attribute as integer or value of defaultNotFound
  256. when name was not found or 0 when value could not be interpreted as integer */
  257. virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound=0) const = 0;
  258. //! Returns the value of an attribute as integer.
  259. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
  260. \param defaultNotFound Value returned when index does not exist.
  261. \return Value of the attribute as integer or value of defaultNotFound parameter for invalid index
  262. or 0 when value could not be interpreted as integer */
  263. virtual int getAttributeValueAsInt(int idx, int defaultNotFound=0) const = 0;
  264. //! Returns the value of an attribute as float.
  265. /** \param name: Name of the attribute.
  266. \param defaultNotFound Value returned when name does not exist.
  267. \return Value of the attribute as float or value of defaultNotFound parameter on failure
  268. or 0 when value could not be interpreted as float. */
  269. virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound=0.f) const = 0;
  270. //! Returns the value of an attribute as float.
  271. /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
  272. \param defaultNotFound Value returned when index does not exist.
  273. \return Value of the attribute as float or value of defaultNotFound parameter on failure
  274. or 0 when value could not be interpreted as float. */
  275. virtual float getAttributeValueAsFloat(int idx, float defaultNotFound=0.f) const = 0;
  276. //! Returns the name of the current node.
  277. /** Only valid, if the node type is EXN_ELEMENT.
  278. \return Name of the current node or 0 if the node has no name. */
  279. virtual const char_type* getNodeName() const = 0;
  280. //! Returns data of the current node.
  281. /** Only valid if the node has some
  282. data and it is of type EXN_TEXT, EXN_COMMENT, EXN_CDATA or EXN_UNKNOWN. */
  283. virtual const char_type* getNodeData() const = 0;
  284. //! Returns if an element is an empty element, like &lt;foo />
  285. virtual bool isEmptyElement() const = 0;
  286. //! Returns format of the source xml file.
  287. /** It is not necessary to use
  288. this method because the parser will convert the input file format
  289. to the format wanted by the user when creating the parser. This
  290. method is useful to get/display additional information. */
  291. virtual ETEXT_FORMAT getSourceFormat() const = 0;
  292. //! Returns format of the strings returned by the parser.
  293. /** This will be UTF8 for example when you created a parser with
  294. IrrXMLReaderUTF8() and UTF32 when it has been created using
  295. IrrXMLReaderUTF32. It should not be necessary to call this
  296. method and only exists for informational purposes. */
  297. virtual ETEXT_FORMAT getParserFormat() const = 0;
  298. };
  299. //! Interface providing methods for making it easier to write XML files.
  300. template<class char_type, class super_class>
  301. class IIrrXMLWriter : public super_class
  302. {
  303. public:
  304. //! Destructor
  305. virtual ~IIrrXMLWriter() {}
  306. //! Writes an xml 1.0 header.
  307. /** Looks like &lt;?xml version="1.0"?&gt;. This should always
  308. be called before writing anything other, because also the text
  309. file header for Unicode texts is written out with this method. */
  310. virtual void writeXMLHeader() = 0;
  311. //! Writes an xml element with maximal 5 attributes like "<foo />" or
  312. //! &lt;foo optAttr="value" /&gt;.
  313. /** The element can be empty or not.
  314. \param name: Name of the element
  315. \param empty: Specifies if the element should be empty. Like
  316. "<foo />". If You set this to false, something like this is
  317. written instead: "<foo>".
  318. \param attr1Name: 1st attributes name
  319. \param attr1Value: 1st attributes value
  320. \param attr2Name: 2nd attributes name
  321. \param attr2Value: 2nd attributes value
  322. \param attr3Name: 3rd attributes name
  323. \param attr3Value: 3rd attributes value
  324. \param attr4Name: 4th attributes name
  325. \param attr4Value: 4th attributes value
  326. \param attr5Name: 5th attributes name
  327. \param attr5Value: 5th attributes value */
  328. virtual void writeElement(const char_type* name, bool empty=false,
  329. const char_type* attr1Name = 0, const char_type* attr1Value = 0,
  330. const char_type* attr2Name = 0, const char_type* attr2Value = 0,
  331. const char_type* attr3Name = 0, const char_type* attr3Value = 0,
  332. const char_type* attr4Name = 0, const char_type* attr4Value = 0,
  333. const char_type* attr5Name = 0, const char_type* attr5Value = 0) = 0;
  334. //! Writes an xml element with any number of attributes
  335. virtual void writeElement(const char_type* name, bool empty,
  336. core::array<core::string<char_type> > &names, core::array<core::string<char_type> > &values) = 0;
  337. //! Writes a comment into the xml file
  338. virtual void writeComment(const char_type* comment) = 0;
  339. //! Writes the closing tag for an element. Like "</foo>"
  340. virtual void writeClosingTag(const char_type* name) = 0;
  341. //! Writes a text into the file.
  342. /** All occurrences of special characters such as
  343. & (&amp;), < (&lt;), > (&gt;), and " (&quot;) are automatically
  344. replaced. */
  345. virtual void writeText(const char_type* text) = 0;
  346. //! Writes a line break
  347. virtual void writeLineBreak() = 0;
  348. };
  349. template <typename T>
  350. struct xmlChar
  351. {
  352. T c;
  353. xmlChar<T>() {}
  354. xmlChar<T>(char in) : c(static_cast<T>(in)) {}
  355. xmlChar<T>(wchar_t in) : c(static_cast<T>(in)) {}
  356. #if defined(__BORLANDC__)
  357. // Note - removing explicit for Borland was to get it to even compile.
  358. // There haven't been any kind of tests for that besides that.
  359. xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
  360. xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
  361. xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
  362. xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
  363. #else
  364. explicit xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
  365. #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) // VS compiling without native wchar_t can't have it
  366. explicit xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
  367. #endif
  368. explicit xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
  369. explicit xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
  370. #endif
  371. operator T() const { return c; }
  372. void operator=(int t) { c=static_cast<T>(t); }
  373. };
  374. //! defines the utf-16 type.
  375. /** Not using wchar_t for this because
  376. wchar_t has 16 bit on windows and 32 bit on other operating systems. */
  377. typedef xmlChar<unsigned short> char16;
  378. //! defines the utf-32 type.
  379. /** Not using wchar_t for this because
  380. wchar_t has 16 bit on windows and 32 bit on other operating systems. */
  381. typedef xmlChar<unsigned int> char32;
  382. //! A UTF-8 or ASCII character xml parser.
  383. /** This means that all character data will be returned in 8 bit ASCII or UTF-8 by this parser.
  384. The file to read can be in any format, it will be converted to UTF-8 if it is not
  385. in this format.
  386. Create an instance of this with createIrrXMLReader();
  387. See IIrrXMLReader for description on how to use it. */
  388. typedef IIrrXMLReader<char, IXMLBase> IrrXMLReader;
  389. //! A UTF-16 xml parser.
  390. /** This means that all character data will be returned in UTF-16 by this parser.
  391. The file to read can be in any format, it will be converted to UTF-16 if it is not
  392. in this format.
  393. Create an instance of this with createIrrXMLReaderUTF16();
  394. See IIrrXMLReader for description on how to use it. */
  395. typedef IIrrXMLReader<char16, IXMLBase> IrrXMLReaderUTF16;
  396. //! A UTF-32 xml parser.
  397. /** This means that all character data will be returned in UTF-32 by this parser.
  398. The file to read can be in any format, it will be converted to UTF-32 if it is not
  399. in this format.
  400. Create an instance of this with createIrrXMLReaderUTF32();
  401. See IIrrXMLReader for description on how to use it. */
  402. typedef IIrrXMLReader<char32, IXMLBase> IrrXMLReaderUTF32;
  403. #ifdef _IRR_COMPILE_WITH_XML_
  404. //! Creates an instance of an UFT-8 or ASCII character xml parser.
  405. /** This means that all character data will be returned in 8 bit ASCII or UTF-8.
  406. The file to read can be in any format, it will be converted to UTF-8 if it is not in this format.
  407. If you are using the Irrlicht Engine, it is better not to use this function but
  408. IFileSystem::createXMLReaderUTF8() instead.
  409. \param filename: Name of file to be opened.
  410. \return Returns a pointer to the created xml parser. This pointer should be
  411. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  412. and the file could not be opened. */
  413. IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename);
  414. //! Creates an instance of an UFT-8 or ASCII character xml parser.
  415. /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
  416. be in any format, it will be converted to UTF-8 if it is not in this format.
  417. If you are using the Irrlicht Engine, it is better not to use this function but
  418. IFileSystem::createXMLReaderUTF8() instead.
  419. \param file: Pointer to opened file, must have been opened in binary mode, e.g.
  420. using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
  421. \return Returns a pointer to the created xml parser. This pointer should be
  422. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  423. and the file could not be opened. */
  424. IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file);
  425. //! Creates an instance of an UFT-8 or ASCII character xml parser.
  426. /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
  427. be in any format, it will be converted to UTF-8 if it is not in this format.
  428. If you are using the Irrlicht Engine, it is better not to use this function but
  429. IFileSystem::createXMLReaderUTF8() instead.
  430. \param callback: Callback for file read abstraction. Implement your own
  431. callback to make the xml parser read in other things than just files. See
  432. IFileReadCallBack for more information about this.
  433. \param deleteCallback: if true, the callback will be deleted after the file
  434. has been read. Otherwise the caller is responsible for cleaning it up.
  435. \return Returns a pointer to the created xml parser. This pointer should be
  436. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  437. and the file could not be opened. */
  438. IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback,
  439. bool deleteCallback = false);
  440. //! Creates an instance of an UFT-16 xml parser.
  441. /** This means that
  442. all character data will be returned in UTF-16. The file to read can
  443. be in any format, it will be converted to UTF-16 if it is not in this format.
  444. If you are using the Irrlicht Engine, it is better not to use this function but
  445. IFileSystem::createXMLReader() instead.
  446. \param filename: Name of file to be opened.
  447. \return Returns a pointer to the created xml parser. This pointer should be
  448. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  449. and the file could not be opened. */
  450. IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename);
  451. //! Creates an instance of an UFT-16 xml parser.
  452. /** This means that all character data will be returned in UTF-16. The file to read can
  453. be in any format, it will be converted to UTF-16 if it is not in this format.
  454. If you are using the Irrlicht Engine, it is better not to use this function but
  455. IFileSystem::createXMLReader() instead.
  456. \param file: Pointer to opened file, must have been opened in binary mode, e.g.
  457. using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
  458. \return Returns a pointer to the created xml parser. This pointer should be
  459. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  460. and the file could not be opened. */
  461. IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file);
  462. //! Creates an instance of an UFT-16 xml parser.
  463. /** This means that all character data will be returned in UTF-16. The file to read can
  464. be in any format, it will be converted to UTF-16 if it is not in this format.
  465. If you are using the Irrlicht Engine, it is better not to use this function but
  466. IFileSystem::createXMLReader() instead.
  467. \param callback: Callback for file read abstraction. Implement your own
  468. callback to make the xml parser read in other things than just files. See
  469. IFileReadCallBack for more information about this.
  470. \param deleteCallback: if true, the callback will be deleted after the file
  471. has been read. Otherwise the caller is responsible for cleaning it up.
  472. \return Returns a pointer to the created xml parser. This pointer should be
  473. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  474. and the file could not be opened. */
  475. IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback,
  476. bool deleteCallback = false);
  477. //! Creates an instance of an UFT-32 xml parser.
  478. /** This means that all character data will be returned in UTF-32. The file to read can
  479. be in any format, it will be converted to UTF-32 if it is not in this format.
  480. If you are using the Irrlicht Engine, it is better not to use this function but
  481. IFileSystem::createXMLReader() instead.
  482. \param filename: Name of file to be opened.
  483. \return Returns a pointer to the created xml parser. This pointer should be
  484. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  485. and the file could not be opened. */
  486. IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename);
  487. //! Creates an instance of an UFT-32 xml parser.
  488. /** This means that all character data will be returned in UTF-32. The file to read can
  489. be in any format, it will be converted to UTF-32 if it is not in this format.
  490. if you are using the Irrlicht Engine, it is better not to use this function but
  491. IFileSystem::createXMLReader() instead.
  492. \param file: Pointer to opened file, must have been opened in binary mode, e.g.
  493. using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
  494. \return Returns a pointer to the created xml parser. This pointer should be
  495. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  496. and the file could not be opened. */
  497. IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file);
  498. //! Creates an instance of an UFT-32 xml parser.
  499. /** This means that
  500. all character data will be returned in UTF-32. The file to read can
  501. be in any format, it will be converted to UTF-32 if it is not in this format.
  502. If you are using the Irrlicht Engine, it is better not to use this function but
  503. IFileSystem::createXMLReader() instead.
  504. \param callback: Callback for file read abstraction. Implement your own
  505. callback to make the xml parser read in other things than just files. See
  506. IFileReadCallBack for more information about this.
  507. \param deleteCallback: if true, the callback will be deleted after the file
  508. has been read. Otherwise the caller is responsible for cleaning it up.
  509. \return Returns a pointer to the created xml parser. This pointer should be
  510. deleted using 'delete' after no longer needed. Returns 0 if an error occurred
  511. and the file could not be opened. */
  512. IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(IFileReadCallBack* callback,
  513. bool deleteCallback = false);
  514. #endif // _IRR_COMPILE_WITH_XML_
  515. /*! \file irrXML.h
  516. \brief Header file of the irrXML, the Irrlicht XML parser.
  517. This file includes everything needed for using irrXML,
  518. the XML parser of the Irrlicht Engine. To use irrXML,
  519. you only need to include this file in your project:
  520. \code
  521. #include <irrXML.h>
  522. \endcode
  523. It is also common to use the two namespaces in which irrXML is included,
  524. directly after including irrXML.h:
  525. \code
  526. #include <irrXML.h>
  527. using namespace irr;
  528. using namespace io;
  529. \endcode
  530. */
  531. } // end namespace io
  532. } // end namespace irr
  533. #endif // IRR_XML_H_INCLUDED