import lxml
from lxml import etree
xml='<?xml version="1.0"?><outputTree xmlns="http://w...content-available-to-author-only...m.com/software/analytics/spss/xml/oms" '\
'xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://w...content-available-to-author-only...m.com/software/analytics/spss/xml/oms'\
'http://w...content-available-to-author-only...m.com/software/analytics/spss/xml/oms/spss-output-1.8.xsd">'\
'<command command="Frequencies" displayOutlineValues="label" displayOutlineVariables="label" displayTableValues="label" displayTableVariables="label" '\
'lang="en" text="Frequencies"><pivotTable label="Gender" subType="Frequencies" text="Gender" varName="gender" variable="true">'\
'<dimension axis="row" label="Gender" text="Gender" varName="gender" variable="true"><group text="Valid"> '\
'<group hide="true" number="0" text="0"><group hide="true" number="-1" text="-1">'\
'<category label="Female" string="f" text="Female" varName="gender">'\
'<dimension axis="column" text="Statistics"><category text="Frequency">'\
'<cell number="216" text="216"/></category><category text="Percent">'\
'<cell decimals="1" number="45.569620253165" text="45,6"/></category><category text="Valid Percent">'\
'<cell decimals="1" number="45.569620253165" text="45,6"/></category><category text="Cumulative Percent">'\
'<cell decimals="1" number="45.569620253165" text="45,6"/></category></dimension></category>'\
'<category label="Male" string="m" text="Male" varName="gender">'\
'<dimension axis="column" text="Statistics"><category text="Frequency">'\
'<cell number="258" text="258"/></category><category text="Percent">'\
'<cell decimals="1" number="54.430379746835" text="54,4"/></category><category text="Valid Percent">'\
'<cell decimals="1" number="54.430379746835" text="54,4"/></category><category text="Cumulative Percent">'\
'<cell decimals="1" number="100" text="100,0"/></category></dimension></category></group></group>'\
'<category text="Total"><dimension axis="column" text="Statistics"><category text="Frequency"><cell number="474" text="474"/>'\
'</category><category text="Percent"><cell decimals="1" number="100" text="100,0"/></category><category text="Valid Percent">'\
'<cell decimals="1" number="100" text="100,0"/></category></dimension></category></group></dimension></pivotTable></command></outputTree>'
tree7=etree.XML(xml)
#tree7 = etree.parse ('c:\\py\\xmltest7.xml')
print ("Tree7: ", tree7)
print ("Type tree7:", type(tree7))
xpath_string7='/outputTree/command/pivotTable[@varName="gender"]'
nodes= tree7.xpath(xpath_string7)
print(type(nodes))
print(len(nodes))
for node in nodes:
print(type(node))
print(node.tag, node.keys(), node.values())