gitmyhub

tinyxml2

C++ ★ 5.8k updated 1mo ago

TinyXML2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs.

TinyXML-2 is a minimal C++ XML library consisting of just one header and one source file, making it easy to drop into any project including game engines and embedded systems where memory and binary size are constrained.

C++setup: easycomplexity 2/5

TinyXML-2 is a small C++ library for reading and writing XML files. XML is a text format used to store structured data, with tags and attributes much like HTML. TinyXML-2 reads an XML file and builds it into a tree of objects in memory, which your C++ code can then navigate, modify, and write back out.

The entire library is just one header file and one source file, so adding it to a project is as simple as dropping in those two files. It does not require any standard library containers, exception handling, or runtime type information, which makes it particularly suitable for environments with limited resources, such as game engines or embedded systems. The README notes that TinyXML-2 was specifically rewritten from its predecessor to use less memory and fewer memory allocations compared to TinyXML-1.

When TinyXML-2 parses a document, it creates an XMLDocument object that owns all the elements, text nodes, attributes, and comments inside it. You access parts of the tree by traversing from the root down through child elements. You can also build an XML document from scratch in code and write it to a file or a memory buffer, or stream XML output directly without constructing a document at all.

The library handles UTF-8 text, recognizes standard XML character entities such as ampersand and less-than signs, and supports numeric character references for Unicode code points. It offers three whitespace handling modes: preserve (the default, which keeps spacing inside text but not between elements), collapse (which strips leading and trailing spaces), and pedantic (which records all whitespace including between elements). Error messages include the line number where a parse problem occurred.

TinyXML-2 does not support DTD validation or XSLT stylesheets. It is released under the ZLib license, which allows use in both open source and commercial projects.

Where it fits