Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. def path_parser(target, path):
  2.   if isinstance(target, dict):
  3.     for k in target:
  4.       path += "/{}".format(k)
  5.       if isinstance(target[k], dict) or isinstance(target[k], list):
  6.         path_parser(target[k], path)
  7.       else:
  8.         reversed[path] = target.get(k)
  9.   elif isinstance(target, list):
  10.     count = 0
  11.     save_path = path
  12.     for k in target:
  13.       path += "/{}".format(count)
  14.       if isinstance(k, dict) or isinstance(k, list):
  15.         path_parser(k, save_path + "/{}".format(count))
  16.       else:
  17.         reversed[path] = k
  18.       count += 1
  19.  
  20. with open('/home/lutsenko/Downloads/response.xml', 'r') as content_file:
  21.     xml = content_file.read()
  22.  
  23. xdict = xmltodict.parse(xml)
  24.  
  25. path_parser(xdict, path)
  26. pprint.pprint(reversed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement