TinyXML-2 Documentation

repository·master·Indexed 26 days ago

https://github.com/leethomason/tinyxml2

A small, efficient C++ XML parser that builds a Document Object Model (DOM) for reading, modifying, and saving XML data. It provides tools for loading files via XMLDocument, navigating the DOM using functions like FirstChildElement and GetText, and configuring whitespace handling modes.

Tokens
559
Snippets
3
Records
4
Agent score
41%

What's inside TinyXML-2

  1. Install TinyXML-2

    master

    TinyXML-2 is designed for easy integration. You can simply include tinyxml2.cpp and tinyxml2.h in your project and build them alongside your other source code. Alternatively, you can use the vcpkg dependency manager to install it.

    git clone https://github.com/Microsoft/vcpkg.git
    cd vcpkg
    ./bootstrap-vcpkg.sh
    ./vcpkg integrate install
    ./vcpkg install tinyxml2
  2. Navigate and lookup XML information

    master

    You can navigate the Document Object Model (DOM) using convenience functions like FirstChildElement(name) and GetText(). For more granular control, you can access nodes as XMLText objects using ToText() and retrieve their values via Value().

    {
    	XMLDocument doc;
    	doc.LoadFile("dream.xml");
    
    	// Navigate to the title using convenience functions
    	const char* title = doc.FirstChildElement("PLAY")->FirstChildElement("TITLE")->GetText();
    	printf("Name of play (1): %s\n", title);
    
    	// Navigate using the more general XMLText node approach
    	XMLText* textNode = doc.FirstChildElement("PLAY")->FirstChildElement("TITLE")->FirstChild()->ToText();
    	title = textNode->Value();
    	printf("Name of play (2): %s\n", title);
    }
  3. Configure XML whitespace modes

    master

    TinyXML-2 provides different whitespace handling modes via the XMLDocument constructor:

    • PRESERVE_WHITESPACE (Default): Preserves whitespace within text nodes and normalizes line endings. It does not preserve whitespace between elements.
    • COLLAPSE_WHITESPACE: Provides