improve xml generation with clear tree structure