I'm curious about the proper way to iterate through the dictionary object generated by xmltodict.py utilities. I've successfully connected to a Nexus 9508 XML API and fed the XML into the parser to get a dictionary object.
I don't have a ton of experience with python dictionaries, and what I do have, wasn't hierarchical like this is. Here's what I have thus far:
ROW_prefix [OrderedDict([(u'ipprefix', u'9.0.0.0/8'), (u'ucast-nhops', u'1'), (u'mcast-nhops', u'0'), (u'attached', u'FALSE'), (u'TABLE_path', OrderedDict([(u'ROW_path', OrderedDict([(u'uptime', u'PT10H1M21S'), (u'pref', u'1'), (u'metric', u'0'), (u'clientname', u'static'), (u'ubest', u'TRUE')]))]))]), OrderedDict([(u'ipprefix', u'172.16.1.0/30'), (u'ucast-nhops', u'1'), (u'mcast-nhops', u'0'), (u'attached', u'TRUE'), (u'TABLE_path', OrderedDict([(u'ROW_path', OrderedDict([(u'ipnexthop', u'172.16.1.2'), (u'ifname', u'Po1'), (u'uptime', u'PT21H59M20S'), (u'pref', u'0'), (u'metric', u'0'), (u'clientname', u'direct'), (u'ubest', u'TRUE')]))]))]), OrderedDict([(u'ipprefix', u'172.16.1.2/32'), (u'ucast-nhops', u'1'), (u'mcast-nhops', u'0'), (u'attached', u'TRUE'), (u'TABLE_path', OrderedDict([(u'ROW_path', OrderedDict([(u'ipnexthop', u'172.16.1.2'), (u'ifname', u'Po1'), (u'uptime', u'PT21H59M20S'), (u'pref', u'0'), (u'metric', u'0'), (u'clientname', u'local'), (u'ubest', u'TRUE')]))]))]), OrderedDict([(u'ipprefix', u'172.16.3.1/32'), (u'ucast-nhops', u'1'), (u'mcast-nhops', u'0'), (u'attached', u'FALSE'), (u'TABLE_path', OrderedDict([(u'ROW_path', OrderedDict([(u'ipnexthop', u'172.16.1.1'), (u'ifname', u'Po1'), (u'uptime', u'PT21H57M59S'), (u'pref', u'110'), (u'metric', u'2'), (u'clientname', u'ospf-1'), (u'type', u'intra'), (u'ubest', u'TRUE')]))]))]), OrderedDict([(u'ipprefix', u'172.16.33.1/32'), (u'ucast-nhops', u'1'), (u'mcast-nhops', u'0'), (u'attached', u'FALSE'), (u'TABLE_path', OrderedDict([(u'ROW_path', OrderedDict([(u'ipnexthop', u'172.16.1.1'), (u'ifname', u'Po1'), (u'uptime', u'PT21H57M59S'), (u'pref', u'110'), (u'metric', u'2'), (u'clientname', u'ospf-1'), (u'type', u'inter'), (u'ubest', u'TRUE')]))]))]), OrderedDict([(u'ipprefix', u'172.16.41.1/32'), (u'ucast-nhops', u'1'), (u'mcast-nhops', u'0'), (u'attached', u'FALSE'), (u'TABLE_path', OrderedDict([(u'ROW_path', OrderedDict([(u'ipnexthop', u'172.16.1.1'), (u'ifname', u'Po1'), (u'uptime', u'PT21H57M59S'), (u'pref', u'110'), (u'metric', u'2'), (u'clientname', u'ospf-1'), (u'type', u'inter'), (u'ubest', u'TRUE')]))]))])]
I was hoping to get to the point where I could create a few classes of my own (for instance a "route" class or similar to represent an entry in the routing table, but I'm at a loss as to how to iterate with what's here. I basically want to iterate through each item under TABLE_prefix, and for each ROW_prefix, add all of the properties within to a class object I can create later. It's the iterating part where I'm stuck.