"""
parsetei.py
(C) 2011 by Damir Cavar <dcavar@me.com>
See: Python 3 for (Computational and Corpus) Linguists
URL: http://www.cavar.me/damir/py4cl/
The general idea is taken from Dive into Python 3, Chapter on XML
http://diveintopython3.ep.io/xml.html
Opens XML files and prints some nodes and their content.
"""
import sys
import xml.etree.ElementTree as etree
def parseXML(file):
if file[-4:] == ".xml":
print(file)
tree = etree.parse(file)
root = tree.getroot()
print(root)
print(root.tag)
print(root.attrib)
for child in root:
print("Child of root:", child)
for subchild in child:
print("Subchild", subchild)
if __name__ == '__main__':
for i in sys.argv[1:]:
parseXML(i)