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