The goal was to write a simple fluent and recursive tag builder.
Simple – means the implementation should be as short as possible.
Fluent – means a fluent interface
Recursive – means that tags could possibly be nested one inside the other.
The implementation is as follows:
Note that I can nest the hierarchy plus I can have two or more tags one beside the other (siblings). The output of this example call is:
Feel free to modify the code. An example extension would be to implement indentation.