Generate a contents tree according to given string