Implementing a tree based XML parser in java