#!/usr/bin/python # -*- coding: utf-8 -*- # -------------------------------------------------- # File Name: test.py # Location: # Purpose: # Creation Date: 25-05-2017 # Last Modified: Thu, May 25, 2017 11:34:12 AM # Author(s): Mike Stout # Copyright 2017 The Author(s) All Rights Reserved # Credits: # -------------------------------------------------- import sys from lxml import etree fname = sys.argv[1] el = sys.argv[2] att = sys.argv[3] val = sys.argv[4] parser = etree.XMLParser(dtd_validation=True) tree = etree.parse(fname, parser) sp="//"+el+"[@"+att+"=\""+val+"\"]" print sp elems = tree.getroot().xpath(sp) ss = tree.xpath(sp+"/speaker/text()") ls = tree.xpath(sp+"/l/text()") for a in zip(ss,ls): print a print "-"*80