#!/usr/bin/env python # -*- coding: utf8 -*- import sys import xml.etree.cElementTree as etree xmlstring = sys.stdin.read() root = etree.XML(xmlstring) bag_of_paths = set() def print_path_of_elems(elem, elem_path=""): global bag_of_paths #print "t" for child in elem: #print "o" if not child.getchildren(): # leaf node with text => print #print "%s/%s, %s" % (elem_path, child.tag, child.text) bag_of_paths.add("%s/%s" % (elem_path, child.tag)) #print elem_path else: # node with child elements => recurse print_path_of_elems(child, "%s/%s" % (elem_path, child.tag)) print_path_of_elems(root, root.tag) print "\n".join(bag_of_paths)