Not fully sure I understand those requirements, but since you mentioned XML perhaps something like JDOM would help. You can build tree-like data structures, and convert those to and from xml.