script to build hierarchical xml from flat data