fork download
  1. import lxml
  2. from lxml import etree
  3. xml='<?xml version="1.0"?><outputTree xmlns="http://w...content-available-to-author-only...m.com/software/analytics/spss/xml/oms" '\
  4. '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'\
  5. 'http://w...content-available-to-author-only...m.com/software/analytics/spss/xml/oms/spss-output-1.8.xsd">'\
  6. '<command command="Frequencies" displayOutlineValues="label" displayOutlineVariables="label" displayTableValues="label" displayTableVariables="label" '\
  7. 'lang="en" text="Frequencies"><pivotTable label="Gender" subType="Frequencies" text="Gender" varName="gender" variable="true">'\
  8. '<dimension axis="row" label="Gender" text="Gender" varName="gender" variable="true"><group text="Valid"> '\
  9. '<group hide="true" number="0" text="0"><group hide="true" number="-1" text="-1">'\
  10. '<category label="Female" string="f" text="Female" varName="gender">'\
  11. '<dimension axis="column" text="Statistics"><category text="Frequency">'\
  12. '<cell number="216" text="216"/></category><category text="Percent">'\
  13. '<cell decimals="1" number="45.569620253165" text="45,6"/></category><category text="Valid Percent">'\
  14. '<cell decimals="1" number="45.569620253165" text="45,6"/></category><category text="Cumulative Percent">'\
  15. '<cell decimals="1" number="45.569620253165" text="45,6"/></category></dimension></category>'\
  16. '<category label="Male" string="m" text="Male" varName="gender">'\
  17. '<dimension axis="column" text="Statistics"><category text="Frequency">'\
  18. '<cell number="258" text="258"/></category><category text="Percent">'\
  19. '<cell decimals="1" number="54.430379746835" text="54,4"/></category><category text="Valid Percent">'\
  20. '<cell decimals="1" number="54.430379746835" text="54,4"/></category><category text="Cumulative Percent">'\
  21. '<cell decimals="1" number="100" text="100,0"/></category></dimension></category></group></group>'\
  22. '<category text="Total"><dimension axis="column" text="Statistics"><category text="Frequency"><cell number="474" text="474"/>'\
  23. '</category><category text="Percent"><cell decimals="1" number="100" text="100,0"/></category><category text="Valid Percent">'\
  24. '<cell decimals="1" number="100" text="100,0"/></category></dimension></category></group></dimension></pivotTable></command></outputTree>'
  25.  
  26. tree7=etree.XML(xml)
  27. #tree7 = etree.parse ('c:\\py\\xmltest7.xml')
  28. print ("Tree7: ", tree7)
  29. print ("Type tree7:", type(tree7))
  30. xpath_string7='/outputTree/command/pivotTable[@varName="gender"]'
  31. nodes= tree7.xpath(xpath_string7)
  32. print(type(nodes))
  33. print(len(nodes))
  34. for node in nodes:
  35. print(type(node))
  36. print(node.tag, node.keys(), node.values())
Runtime error #stdin #stdout #stderr 0.02s 47720KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "<builtin>/app_main.py", line 75, in run_toplevel
  File "prog.py", line 1, in <module>
    import lxml
ImportError: No module named lxml