If the items can't be counted on to be in hierarchical sequence, and the number of levels can vary then it presents a coding challenge. Could you please attach actual data, or at least a more representative sample? The above attachment isn't really enough to go on.