Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2. tree = ET.parse('smp.xml')
  3. root = tree.getroot()
  4.  
  5. for text in root.iter('text'):
  6. print(text.attrib)
  7.  
  8. for text in root.iter('text'):
  9. print(text.text)
  10.  
  11. <?xml version="1.0"?>
  12. <doc>
  13. <page index="0"/>
  14. <page index="1">
  15. <row>
  16. <column>
  17. <text>fibrous drupe</text>
  18. </column>
  19. </row>
  20. <row>
  21. <column>
  22. <text>follicle</text>
  23. </column>
  24. <column>
  25. <text>legume</text>
  26. </column>
  27. </row>
  28. <row>
  29. <column>
  30. <text>loment</text>
  31. </column>
  32. <column>
  33. <text>nut</text>
  34. </column>
  35. <column>
  36. <text>samara</text>
  37. </column>
  38. </row>
  39. <row>
  40. <column>
  41. <text>schizocarp</text>
  42. </column>
  43. </row>
  44. </page>
  45. <page index="2">
  46. <row>
  47. <column>
  48. <text>cypsela</text>
  49. </column>
  50. </row>
  51. </page>
  52. <page index="3"/>
  53. </doc>
  54.  
  55. <?xml version="1.0"?>
  56. <doc>
  57. <page index="0"/>
  58. <page index="1">
  59. <row index="0">
  60. <column index="0">
  61. <text>fibrous drupe</text>
  62. </column>
  63. </row>
  64. <row index="1">
  65. <column index="0">
  66. <text>follicle</text>
  67. </column>
  68. <column index="1">
  69. <text>legume</text>
  70. </column>
  71. </row>
  72. <row index="2">
  73. <column index="0">
  74. <text>loment</text>
  75. </column>
  76. <column index="1">
  77. <text>nut</text>
  78. </column>
  79. <column index="2">
  80. <text>samara</text>
  81. </column>
  82. </row>
  83. <row index="3">
  84. <column index="0">
  85. <text>schizocarp</text>
  86. </column>
  87. </row>
  88. </page>
  89. <page index="2">
  90. <row index="0">
  91. <column index="0">
  92. <text>cypsela</text>
  93. </column>
  94. </row>
  95. </page>
  96. <page index="3"/>
  97. </doc>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement