Core of XTLP are two classes - xtlpRoot and xtlpNode.
Their definition looks like:
public class xtlpNode
{
   public String Name;
   public TreeMap<String, String> Pairs;
   public ArrayList<xtlpNode> Childs;
}
public class xtlpRoot
{
   public ArrayList<xtlpNode> Nodes;
}
xtlpNode
Every xtlpNode 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.
xtlpRoot
This class handles nodes allocations and deallocations, reads XTL files and processes its content into tree representation. To read XTL file you have to simply create object of xtlpRoot with parametrized constructor. Path into XTL file is enough. After load process all nodes in root scope are available in returned xtlpRoot objects through
Nodes member.
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 Java code in Test.java:
import java.util.ArrayList;
import xtlp.xtlpNode;
import xtlp.xtlpRoot;
public class Test
{
   private static void DisplayContent(ArrayList<xtlpNode> Nodes)
   {
      for (var N : Nodes)
      {
         System.out.println(String.format("Node name: %s", N.Name));
         for (var P : N.Pairs.entrySet())
         {
            System.out.println(String.format("Pair: %s = %s", P.getKey(), P.getValue()));
         }
         DisplayContent(N.Childs);
      }
   }
   public static void main(String[] args)
   {
      try
      {
         xtlpRoot Root = new xtlpRoot("cfg.xtl");
         Test.DisplayContent(Root.Nodes);
      }
      catch(java.io.IOException e)
      {
         System.err.println("IOERROR");
      }
   }
}
As you can see code is simple. Just create xtlpRoot object and it is everything. Now we can easily iterate over XTL tree and print its content recursively. This is what we are doing in
Test.DisplayContent method.
You may ask why everything is in
try-catch clausule - we must handle exception when for example our XTL file does not exist. So now, we can build our code:
$ javac Test.java
$ jar cf test.jar Test.class
$ java -cp ".:libxtlp-100-j21.jar" Test
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.