---------------------------------------------------------------
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
def _convert_xml_to_dict_list (file_name):
keyword_name = "_convert_xml_to_dict_list "
try :
tree = ET.parse(file_name)
for child in tree.iter() :
print ("tag:%s, attrib:%s" % (child.tag,child.attrib))
except Exception as inst :
s=sys.exc_info()
raise AssertionError("%s:%s-> fail to parse xml to dict list, line: %s, excpetion: %s" \
% (__name__, keyword_name, s[2].tb_lineno, str(inst)))
-------------------------------------------------------------------------------
Pay attathen to tag and attrib:
tag:pdml, attrib:{'capture_file': '/home/qihz/dump_eth0.pcap', 'version': '0', 'time': 'Wed Aug 10 23:10:31 2016', 'creator': 'wireshark/1.10.0'}
tag:packet, attrib:{} tag:proto, attrib:{'size': '60', 'name': 'geninfo', 'showname': 'General information', 'pos': '0'}
tag:field, attrib:{'name': 'num', 'show': '4', 'pos': '0', 'value': '4', 'showname': 'Number', 'size': '60'}
tag:field, attrib:{'name': 'len', 'show': '60', 'pos': '0', 'value': '3c', 'showname': 'Frame Length', 'size': '60'}
tag:field, attrib:{'name': 'caplen', 'show': '60', 'pos': '0', 'value': '3c', 'showname': 'Captured Length', 'size': '60'}