readme.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /** @mainpage
  2. <h1> TinyXml </h1>
  3. TinyXml is a simple, small, C++ XML parser that can be easily
  4. integrating into other programs.
  5. <h2> What it does. </h2>
  6. In brief, TinyXml parses an XML document, and builds from that a
  7. Document Object Model that can be read, modified, and saved.
  8. XML stands for "eXtensible Markup Language." It allows you to create
  9. your own document markups. Where HTML does a very good job of marking
  10. documents for browsers, XML allows you to define any kind of document
  11. markup, for example a document that describes a "to do" list for an
  12. organizer application. XML is a very structured and convenient format.
  13. All those random file formats created to store application data can
  14. all be replaced with XML. One parser for everything.
  15. There are different ways to access and interact with XML data.
  16. TinyXml uses a Document Object Model, meaning the XML data is parsed
  17. into a tree objects that can be browsed and manipulated, and then
  18. written back to disk. You can also construct an XML document from
  19. scratch with C++ objects and write this to disk.
  20. TinyXml is designed to be easy and fast. It is one header and three cpp
  21. files. Simply add these to your project and off you go. There is an
  22. example to get you started. It is released under the ZLib license,
  23. so you can use it in open source or commercial code.
  24. It attempts to be a flexible parser, but with truly correct and
  25. compliant XML output (with the exception of the character set,
  26. below.) TinyXml should compile on any reasonably C++
  27. system. It does not rely on exceptions or RTTI, and only uses the STL
  28. string class.
  29. <h2> What it doesn't do. </h2>
  30. It doesn’t parse or use DTDs (Document Type Definitions) or XSL’s
  31. (eXtensible Stylesheet Language.) It is limited to the ASCII
  32. character set. There are other parsers out there (check out
  33. www.sourceforge.org, search for XML) that are much more fully
  34. featured. But they are also much bigger, take longer to set up in
  35. your project, have a higher learning curve, and often have a more
  36. restrictive license. If you are working with browsers or have more
  37. complete XML needs, TinyXml is not the parser for you.
  38. <h2> Code Status. </h2>
  39. Currently in use, TinyXml is looking pretty stable. If you find
  40. bugs, send them in and we'll get them straightened out as soon as possible.
  41. There are some areas of improvement; please check sourceforge if you are
  42. interested in working on TinxXml.
  43. <h2> Changes between version 1 and 2 </h2>
  44. <h3> Entities </h3>
  45. TinyXml recognizes the pre-defined "entity references", meaning special
  46. characters. Namely:
  47. @verbatim
  48. &amp; &
  49. &lt; <
  50. &gt; >
  51. &quot; "
  52. &apos; ‘
  53. @endverbatim
  54. These are recognized when the XML document is read, and translated to there
  55. ASCII equivalents. For instance, text with the XML of:
  56. @verbatim
  57. Far &amp; Away
  58. @endverbatim
  59. will have the Value() of "Far & Away" when queried from the TiXmlText object,
  60. but will be written back to the XML stream/file as an entitity.
  61. TiXml will ignore unknown entities and the
  62. @verbatim
  63. "&#x"
  64. @endverbatim
  65. entities, and leave them unprocessed.
  66. <h3> Streams </h3>
  67. TiXml has been modified to support both C (FILE) and C++ (operator <<,>>)
  68. streams. There are some differences that you may need to be aware of.
  69. C style output:
  70. - based on FILE*
  71. - the Print() and SaveFile() methods
  72. Generates formatted output, with plenty of white space, intended to be as
  73. human-readable as possible. They are very fast, and tolerant of ill formed
  74. XML documents. For example, an XML document that contains 2 root elements
  75. and 2 declarations, will print.
  76. C style input:
  77. - based on FILE*
  78. - the Parse() and LoadFile() methods
  79. A fast, tolerant read. Use whenever you don't need the C++ streams.
  80. C++ style ouput:
  81. - based on std::ostream
  82. - operator<<
  83. Generates condensed output, intended for network transmission rather than
  84. readability. Depending on your system's implementation of the ostream class,
  85. these may be somewhat slower. (Or may not.) Not tolerant of ill formed XML:
  86. a document should contain the correct one root element. Additional root level
  87. elements will not be streamed out.
  88. C++ style input:
  89. - based on std::istream
  90. - operator>>
  91. Reads XML from a stream, making it useful for network transmission. The tricky
  92. part is knowing when the XML document is complete, since there will almost
  93. certainly be other data in the stream. TinyXml will assume the XML data is
  94. complete after it reads the root element. Also not that operator>> is somewhat
  95. slower than Parse, due to both implementation of the STL and limitations of
  96. TinyXml.
  97. <h3> White space </h3>
  98. The world simply does not agree on whether white space should be kept, or condensed.
  99. For example, pretend the '_' is a space, and look at "Hello____world". HTML, and
  100. at least some XML parsers, will interpret this as "Hello_world". They condense white
  101. space. Some XML parsers do not, and will leave it as "Hello____world". (Remember
  102. to keep pretending the _ is a space.)
  103. It's an issue that hasn't been resolved to my satisfaction. TinyXml supports both
  104. motifs. Call TiXmlBase::SetCondenseWhiteSpace( bool ) to set the desired behavior.
  105. The default is to condense white space.
  106. If you change the default, you should call TiXmlBase::SetCondenseWhiteSpace( bool )
  107. before making any calls to Parse XML data, and I don't recommend changing it after
  108. it has been set.
  109. <h2> Using and Installing </h2>
  110. To Compile and Run xmltest:
  111. A Linux Makefile and a Windows Visual C++ .dsp file is provided.
  112. Simply compile and run. It will write the file demotest.xml to your
  113. disk and generate output on the screen. It also tests walking the
  114. DOM by printing out the number of nodes found using different
  115. techniques.
  116. The Linux makefile is very generic and will
  117. probably run on other systems, but is only tested on Linux. You no
  118. longer need to run 'make depend'. The dependecies have been
  119. hard coded.
  120. To Use in an Application:
  121. Add tinyxml.cpp, tinyxml.h, tinyxmlerror.cpp, and tinyxmlparser.cpp to your
  122. project or make file. That's it! It should compile on any reasonably
  123. compliant C++ system. You do not need to enable exceptions or
  124. RTTI for TinyXml.
  125. <h2> Where it may go. </h2>
  126. At this point, I'm focusing on tightening up remaining issues.
  127. Bug fixes (though comfortably rare) and minor interface
  128. corrections.
  129. There are some "it would be nice if..." items. I'll keep those
  130. posted as tasks on SourceForge. (www.sourceforge.net/projects/tinyxml)
  131. <h2> How TinyXml works. </h2>
  132. An example is probably the best way to go. Take:
  133. @verbatim
  134. <?xml version="1.0" standalone=‘no’>
  135. <?-- Our to do list data -->
  136. <ToDo>
  137. <Item priority="1"> Go to the <bold>Toy store!</bold></Item>
  138. <Item priority="2"> Do bills</Item>
  139. </ToDo>
  140. @endverbatim
  141. It’s not much of a To Do list, but it will do. To read this file
  142. (say "demo.xml") you would create a document, and parse it in:
  143. @verbatim
  144. TiXmlDocument doc( "demo.xml" );
  145. doc.LoadFile();
  146. @endverbatim
  147. And it’s ready to go. Now let’s look at some lines and how they
  148. relate to the DOM.
  149. <?xml version="1.0" standalone=‘no’>
  150. The first line is a declaration, and gets turned into the
  151. TiXmlDeclaration class. It will be the first child of the
  152. document node.
  153. This is the only directive/special tag parsed by by TinyXml.
  154. Generally directive targs are stored in TiXmlUnknown so the
  155. commands won’t be lost when it is saved back to disk.
  156. <?-- Our to do list data -->
  157. A comment. Will become a TiXmlComment object.
  158. <ToDo>
  159. The ToDo tag defines a TiXmlElement object. This one does not have
  160. any attributes, but will contain 2 other elements, both of which
  161. are items.
  162. <Item priority="1">
  163. Creates another TiXmlElement which is a child of the "ToDo" element.
  164. This element has 1 attribute, with the name ‘priority’ and the value
  165. ‘1’.
  166. Go to the
  167. A TiXmlText. This is a leaf node and cannot contain other nodes.
  168. It is a child of the ‘Item" Element.
  169. <bold>
  170. Another TiXmlElement, this one a child of the "Item" element.
  171. Etc.
  172. Looking at the entire object tree, you end up with:
  173. @verbatim
  174. TiXmlDocument "demo.xml"
  175. TiXmlDeclaration "version='1.0'" "standalone=‘no’"
  176. TiXmlComment " Our to do list data"
  177. TiXmlElement "ToDo"
  178. TiXmlElement "Item" Attribtutes: priority = 1
  179. TiXmlText "Go to the "
  180. TiXmlElement "bold"
  181. TiXmlText "Toy store!"
  182. TiXmlElement "Item" Attributes: priority=2
  183. TiXmlText "bills"
  184. @endverbatim
  185. <h2> Contributors </h2>
  186. Thanks very much to everyone who sends suggestions, bugs, ideas, and
  187. encouragement. It all helps, and makes this project fun. A special thanks
  188. to the contributors on the web pages that keep it lively.
  189. So many people have sent in bugs and ideas, that rather than list here I
  190. try to give credit due in the "changes.txt" file.
  191. <h2> Documentation </h2>
  192. The documentation is build with Doxygen, using the 'dox'
  193. configuration file.
  194. <h2> License </h2>
  195. TinyXml is released under the zlib license:
  196. This software is provided 'as-is', without any express or implied
  197. warranty. In no event will the authors be held liable for any
  198. damages arising from the use of this software.
  199. Permission is granted to anyone to use this software for any
  200. purpose, including commercial applications, and to alter it and
  201. redistribute it freely, subject to the following restrictions:
  202. 1. The origin of this software must not be misrepresented; you must
  203. not claim that you wrote the original software. If you use this
  204. software in a product, an acknowledgment in the product documentation
  205. would be appreciated but is not required.
  206. 2. Altered source versions must be plainly marked as such, and
  207. must not be misrepresented as being the original software.
  208. 3. This notice may not be removed or altered from any source
  209. distribution.
  210. <h2> References </h2>
  211. The World Wide Web Consortium is the definitive standard body for
  212. XML, and there web pages contain huge amounts of information. I also
  213. recommend "XML Pocket Reference" by Robert Eckstein and published by
  214. O’Reilly.
  215. <h2> Contact Me: </h2>
  216. I’d appreciates your suggestions, and would love to know if you
  217. use TinyXml. I hope you enjoy it and find it useful. Please post
  218. questions, comments, file bugs, or contact me at:
  219. www.sourceforge.net/projects/tinyxml
  220. Lee Thomason
  221. */