Core of XTLP are two classes - XTNode and XTNodesStack.
Their definition looks like:
struct XTNode
{
   std::string Name;
   std::map<std::string, std::string> Pairs;
   std::vector<const XTNode*> Childs;
};
class XTNodesStack
{
public:
   std::vector<const XTNode*> Read(std::string_view FileName);
};
XTNode
Every XTNode represents section of XTL file. Due to every section may be named or unnamed,
Name member may contain empty string.
Pairs are keys and their values defined in node scope.
Access to subsections is done through
Childs member.
XTNodesStack
This class handles nodes allocations and deallocations, reads XTL files and processes its content into tree representation. So lifetime of nodes returned by Read method is equivalent to lifetime XTNodesStack object.
Pay attention for it.
XTNodesStack::Read method as mentioned before - reads and processes XTL files. As argument it takes path into XTL file.
How to use - example
Firstly, define XTL file named cfg.xtl:
<XTH
    v='100'
<students
    <student0
        name='Ben'
        age='23'
    <student1
        name='John
        age='28'
        <grades
            physical_education='4'
            biology='3'
            chemistry='2'
            physics='5'
<
    unnamed_key='ghf'
Now define our C++ code in xtl.cpp:
#include <print>
#include <xtlp.hpp>
void DisplayContent(std::vector<const XTLP::XTNode*> Nodes)
{
    for (auto& N : Nodes)
    {
        std::println("Node name: {0}", N->Name);
        for (auto& P : N->Pairs)
        {
            std::println("Pair: {0} = {1}", P.first, P.second);
        }
        DisplayContent(N->Childs);
    }
}
int main()
{
    XTLP::XTNodesStack XTStack;
    auto Childs = XTStack.Read("cfg.xtl");
    DisplayContent(Childs);
    return 0;
}
We will start overview from
main function. Firstly creation of
XTLP::XTNodesStack object named XTStack is required - we must store somewhere our nodes. Later,
we use
Read method to parse and process all nodes contained in XTL file named
cfg.xtl. All root nodes are returned into
Childs variable.
Next step is just to display recursively all of them (and their pairs) into console. So compile our code, make it executable and run:
$ g++ -std=c++23 -O3 -o xtl_exe xtl.cpp -lxtlp
$ sudo chmod +x xtl_exe
$ ./xtl_exe
Then we will see content of our xtl file:
Node name: XTH
Pair: v = 100
Node name: students
Node name: student0
Pair: age = 23
Pair: name = Ben
Node name: student1
Pair: age = 28
Pair: name = John
Node name: grades
Pair: biology = 3
Pair: chemistry = 2
Pair: physical_education = 4
Pair: physics = 5
Node name: null
Pair: unnamed_key = ghf
Make some attention for node named
null. This is unnamed section - just XTLP automatically renames unnamed sections into
null.