Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.etree.ElementTree as ET
- tree = ET.parse('smp.xml')
- root = tree.getroot()
- for text in root.iter('text'):
- print(text.attrib)
- for text in root.iter('text'):
- print(text.text)
- <?xml version="1.0"?>
- <doc>
- <page index="0"/>
- <page index="1">
- <row>
- <column>
- <text>fibrous drupe</text>
- </column>
- </row>
- <row>
- <column>
- <text>follicle</text>
- </column>
- <column>
- <text>legume</text>
- </column>
- </row>
- <row>
- <column>
- <text>loment</text>
- </column>
- <column>
- <text>nut</text>
- </column>
- <column>
- <text>samara</text>
- </column>
- </row>
- <row>
- <column>
- <text>schizocarp</text>
- </column>
- </row>
- </page>
- <page index="2">
- <row>
- <column>
- <text>cypsela</text>
- </column>
- </row>
- </page>
- <page index="3"/>
- </doc>
- <?xml version="1.0"?>
- <doc>
- <page index="0"/>
- <page index="1">
- <row index="0">
- <column index="0">
- <text>fibrous drupe</text>
- </column>
- </row>
- <row index="1">
- <column index="0">
- <text>follicle</text>
- </column>
- <column index="1">
- <text>legume</text>
- </column>
- </row>
- <row index="2">
- <column index="0">
- <text>loment</text>
- </column>
- <column index="1">
- <text>nut</text>
- </column>
- <column index="2">
- <text>samara</text>
- </column>
- </row>
- <row index="3">
- <column index="0">
- <text>schizocarp</text>
- </column>
- </row>
- </page>
- <page index="2">
- <row index="0">
- <column index="0">
- <text>cypsela</text>
- </column>
- </row>
- </page>
- <page index="3"/>
- </doc>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement