SHARE
TWEET

Untitled

a guest Jul 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import xml.etree.ElementTree as ET
  4. import sys
  5.  
  6. if len(sys.argv) < 3:
  7.     print("Usage xpath.py file expression [attributes]")
  8.     sys.exit(1)
  9.  
  10. def to_string(element, attrs):
  11.     if attrs:
  12.         d = element.attrib
  13.         return ",".join(d.get(a, '-') for a in attrs)
  14.     return str(ET.tostring(element))
  15.  
  16. with open(sys.argv[1]) as fin:
  17.     print('\n'.join((to_string(i, sys.argv[3:]) for i in ET.parse(fin).findall(sys.argv[2]))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top