readme.txt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 uses 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 (1/10th to 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> White Space </h3>
  76. Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx
  77. TinyXML-2 preserves white space in a (hopefully) sane way that is almost complient with the spec.
  78. (TinyXML-1 used a completely outdated model.)
  79. As a first step, all newlines / carriage-returns / line-feeds are normalized to a
  80. line-feed character, as required by the XML spec.
  81. White space in text is preserved. For example:
  82. <element> Hello, World</element>
  83. The leading space before the "Hello" and the double space after the comma are preserved.
  84. Line-feeds are preserved, as in this example:
  85. <element> Hello again,
  86. World</element>
  87. However, white space between elements is *not* preserved. Although not strictly compliant,
  88. tracking and reporting inta-element space is awkward, and not normally valuable. TinyXML-2
  89. sees these as the same XML:
  90. <document>
  91. <data>1</data>
  92. <data>2</data>
  93. <data>3</data>
  94. </document>
  95. <document><data>1</data><data>2</data><data>3</data></document>
  96. <h3> Entities </h3>
  97. TinyXML-2 recognizes the pre-defined "character entities", meaning special
  98. characters. Namely:
  99. &amp; &
  100. &lt; <
  101. &gt; >
  102. &quot; "
  103. &apos; '
  104. These are recognized when the XML document is read, and translated to there
  105. UTF-8 equivalents. For instance, text with the XML of:
  106. Far &amp; Away
  107. will have the Value() of "Far & Away" when queried from the XMLText object,
  108. and will be written back to the XML stream/file as an ampersand.
  109. Additionally, any character can be specified by its Unicode code point:
  110. The syntax "&#xA0;" or "&#160;" are both to the non-breaking space characher.
  111. This is called a 'numeric character reference'. Any numeric character reference
  112. that isn't one of the special entities above, will be read, but written as a
  113. regular code point. The output is correct, but the entity syntax isn't preserved.
  114. <h3> Printing </h3>
  115. <h4> Print to file </h4>
  116. You can directly use the convenience function:
  117. XMLDocument doc;
  118. ...
  119. doc.Save( "foo.xml" );
  120. Or the XMLPrinter class:
  121. XMLPrinter printer( fp );
  122. doc.Print( &printer );
  123. <h4> Print to memory </h4>
  124. Printing to memory is supported by the XMLPrinter.
  125. XMLPrinter printer;
  126. doc->Print( &printer );
  127. // printer.CStr() has a const char* to the XML
  128. <h4> Print without an XMLDocument </h4>
  129. When loading, an XML parser is very useful. However, sometimes
  130. when saving, it just gets in the way. The code is often set up
  131. for streaming, and constructing the DOM is just overhead.
  132. The Printer supports the streaming case. The following code
  133. prints out a trivially simple XML file without ever creating
  134. an XML document.
  135. XMLPrinter printer( fp );
  136. printer.OpenElement( "foo" );
  137. printer.PushAttribute( "foo", "bar" );
  138. printer.CloseElement();
  139. <h2> Using and Installing </h2>
  140. There are 2 files in TinyXML-2:
  141. <ol>
  142. <li>tinyxml2.cpp</li>
  143. <li>tinyxml2.h</li>
  144. </ol>
  145. And additionally a test file:
  146. <ol>
  147. <li>xmltest.cpp</li>
  148. </ol>
  149. Simply compile and run. There is a visual studio 2010 project included.
  150. <h2> Documentation </h2>
  151. The documentation is build with Doxygen, using the 'dox'
  152. configuration file.
  153. <h2> License </h2>
  154. TinyXML-2 is released under the zlib license:
  155. This software is provided 'as-is', without any express or implied
  156. warranty. In no event will the authors be held liable for any
  157. damages arising from the use of this software.
  158. Permission is granted to anyone to use this software for any
  159. purpose, including commercial applications, and to alter it and
  160. redistribute it freely, subject to the following restrictions:
  161. 1. The origin of this software must not be misrepresented; you must
  162. not claim that you wrote the original software. If you use this
  163. software in a product, an acknowledgment in the product documentation
  164. would be appreciated but is not required.
  165. 2. Altered source versions must be plainly marked as such, and
  166. must not be misrepresented as being the original software.
  167. 3. This notice may not be removed or altered from any source
  168. distribution.
  169. <h2> Contributors </h2>
  170. Thanks very much to everyone who sends suggestions, bugs, ideas, and
  171. encouragement. It all helps, and makes this project fun.
  172. The original TinyXML-1 has many contributors, who all deserve thanks
  173. in shaping what is a very successful library. Extra thanks to Yves
  174. Berquin and Andrew Ellerton who were key contributors.
  175. TinyXML-2 grew from that effort. Lee Thomason is the original author
  176. of TinyXML-2 (and TinyXML-1) but hopefully TinyXML-2 will be improved
  177. by many contributors.
  178. */