readme.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* @mainpage
  2. <h1> TinyXML-2 </h1>
  3. TinyXML is a simple, small, efficient, C++ XML parser that can be
  4. easily integrated into other programs.
  5. The master is hosted on github:
  6. github.com/leethomason/tinyxml2
  7. <h2> What it does. </h2>
  8. In brief, TinyXML parses an XML document, and builds from that a
  9. Document Object Model (DOM) that can be read, modified, and saved.
  10. XML stands for "eXtensible Markup Language." It is a general purpose
  11. human and machine readable markup language to describe arbitrary data.
  12. All those random file formats created to store application data can
  13. all be replaced with XML. One parser for everything.
  14. http://en.wikipedia.org/wiki/XML
  15. There are different ways to access and interact with XML data.
  16. TinyXML-2 uses a Document Object Model (DOM), meaning the XML data is parsed
  17. into a C++ objects that can be browsed and manipulated, and then
  18. written to disk or another output stream. You can also construct an XML document
  19. from scratch with C++ objects and write this to disk or another output
  20. stream. You can even use TinyXML-2 to stream XML programmatically from
  21. code without creating a document first.
  22. TinyXML-2 is designed to be easy and fast to learn. It is one header and
  23. one cpp file. Simply add these to your project and off you go.
  24. There is an example file - xmltest.cpp - to get you started.
  25. TinyXML-2 is released under the ZLib license,
  26. so you can use it in open source or commercial code. The details
  27. of the license are at the top of every source file.
  28. TinyXML-2 attempts to be a flexible parser, but with truly correct and
  29. compliant XML output. TinyXML-2 should compile on any reasonably C++
  30. compliant system. It does not rely on exceptions, RTTI, or the STL.
  31. <h2> What it doesn't do. </h2>
  32. TinyXML-2 doesn't parse or use DTDs (Document Type Definitions) or XSLs
  33. (eXtensible Stylesheet Language.) There are other parsers out there
  34. that are much more fully
  35. featured. But they are also much bigger, take longer to set up in
  36. your project, have a higher learning curve, and often have a more
  37. restrictive license. If you are working with browsers or have more
  38. complete XML needs, TinyXML-2 is not the parser for you.
  39. <h2> TinyXML-1 vs. TinyXML-2 </h2>
  40. Which should you use? TinyXML-2 uses a similar API to TinyXML-1 and the same
  41. rich test cases. But the implementation of the parser is completely re-written
  42. to make it more appropriate for use in a game. It uses less memory, is faster,
  43. and user far few memory allocations.
  44. TinyXML-2 has no requirement for STL, but has also dropped all STL support. All
  45. strings are query and set as 'const char*'. This allows the use of internal
  46. allocators, and keeps the code much simpler.
  47. Both parsers:
  48. <ol>
  49. <li>Simple to use with similar APIs.</li>
  50. <li>DOM based parser.</li>
  51. <li>UTF-8 Unicode support. http://en.wikipedia.org/wiki/UTF-8 </li>
  52. </ol>
  53. Advantages of TinyXML-2
  54. <ol>
  55. <li>The focus of all future dev.</li>
  56. <li>Many fewer memory allocation (about 1/100th), uses less memory (about 40% of TinyXML-1), and faster.</li>
  57. <li>No STL requirement.</li>
  58. <li>More modern C++, including a proper namespace.</li>
  59. <li>Proper and useful handling of whitespace</li>
  60. </ol>
  61. Advantages of TinyXML-1
  62. <ol>
  63. <li>Can report the location of parsing errors.</li>
  64. <li>Support for some C++ STL conventions: streams and strings</li>
  65. <li>Very mature and well debugged code base.</li>
  66. </ol>
  67. <h2> Features </h2>
  68. <h3> Memory Model </h3>
  69. An XMLDocument is a C++ object like any other, that can be on the stack, or
  70. new'd and deleted on the heap.
  71. However, any sub-node of the Document, XMLElement, XMLText, etc, can only
  72. be created by calling the appropriate XMLDocument::NewElement, NewText, etc.
  73. method. Although you have pointers to these objects, they are still owned
  74. by the Document. When the Document is deleted, so are all the nodes it contains.
  75. <h3> Entities </h3>
  76. TinyXML-2 recognizes the pre-defined "character entities", meaning special
  77. characters. Namely:
  78. @verbatim
  79. &amp; &
  80. &lt; <
  81. &gt; >
  82. &quot; "
  83. &apos; '
  84. @endverbatim
  85. These are recognized when the XML document is read, and translated to there
  86. UTF-8 equivalents. For instance, text with the XML of:
  87. @verbatim
  88. Far &amp; Away
  89. @endverbatim
  90. will have the Value() of "Far & Away" when queried from the XMLText object,
  91. and will be written back to the XML stream/file as an ampersand.
  92. Additionally, any character can be specified by its Unicode code point:
  93. The syntax "&#xA0;" or "&#160;" are both to the non-breaking space characher.
  94. This is called a 'numeric character reference'. Any numeric character reference
  95. that isn't one of the special entities above, will be read, but written as a
  96. regular code point. The output is correct, but the entity syntax isn't preserved.
  97. <h3> Printing </h3>
  98. <h4> Print to file </h4>
  99. You can directly use the convenience function:
  100. @verbatim
  101. XMLDocument doc;
  102. ...
  103. doc.Save( "foo.xml" );
  104. @endverbatim
  105. Or the XMLPrinter class:
  106. @verbatim
  107. XMLPrinter printer( fp );
  108. doc.Print( &printer );
  109. @endverbatim
  110. <h4> Print to memory </h4>
  111. Printing to memory is supported by the XMLPrinter.
  112. @verbatim
  113. XMLPrinter printer;
  114. doc->Print( &printer );
  115. // printer.CStr() has a const char* to the XML
  116. @endverbatim
  117. <h4> Print without an XMLDocument </h4>
  118. When loading, an XML parser is very useful. However, sometimes
  119. when saving, it just gets in the way. The code is often set up
  120. for streaming, and constructing the DOM is just overhead.
  121. The Printer supports the streaming case. The following code
  122. prints out a trivially simple XML file without ever creating
  123. an XML document.
  124. @verbatim
  125. XMLPrinter printer( fp );
  126. printer.OpenElement( "foo" );
  127. printer.PushAttribute( "foo", "bar" );
  128. printer.CloseElement();
  129. @endverbatim
  130. <h2> Using and Installing </h2>
  131. There are 2 files in TinyXML-2:
  132. <ol>
  133. <li>tinyxml2.cpp</li>
  134. <li>tinyxml2.h</li>
  135. </ol>
  136. And additionally a test file:
  137. <ol>
  138. <li>xmltest.cpp</li>
  139. </ol>
  140. Simply compile and run. There is a visual studio 2010 project included.
  141. <h2> Documentation </h2>
  142. The documentation is build with Doxygen, using the 'dox'
  143. configuration file.
  144. <h2> License </h2>
  145. TinyXML-2 is released under the zlib license:
  146. This software is provided 'as-is', without any express or implied
  147. warranty. In no event will the authors be held liable for any
  148. damages arising from the use of this software.
  149. Permission is granted to anyone to use this software for any
  150. purpose, including commercial applications, and to alter it and
  151. redistribute it freely, subject to the following restrictions:
  152. 1. The origin of this software must not be misrepresented; you must
  153. not claim that you wrote the original software. If you use this
  154. software in a product, an acknowledgment in the product documentation
  155. would be appreciated but is not required.
  156. 2. Altered source versions must be plainly marked as such, and
  157. must not be misrepresented as being the original software.
  158. 3. This notice may not be removed or altered from any source
  159. distribution.
  160. <h2> Contributors </h2>
  161. Thanks very much to everyone who sends suggestions, bugs, ideas, and
  162. encouragement. It all helps, and makes this project fun.
  163. The original TinyXML-1 has many contributors, who all deserve thanks
  164. in shaping what is a very successful library. Extra thanks to Yves
  165. Berquin and Andrew Ellerton who were key contributors.
  166. TinyXML-2 grew from that effort. Lee Thomason is the original author
  167. of TinyXML-2 (and TinyXML-1) but hopefully TinyXML-2 will be improved
  168. by many contributors.
  169. */