Simply find the one tag that matches, then take the .text
attribute:
company = root.find('.//company').text
author = root.find('.//Author').text
Question
xml =
<company>Mcd</company>
<Author>Dr.D</Author>
I want to fetch Mcd and Dr.D.
My try
import xml.etree.ElementTree as et
e = et.parse(xml)
root = e.getroot()
for node in root.getiterator("company"):
print node.tag
Hopping for a generous help.
Solution
Simply find the one tag that matches, then take the .text
attribute:
company = root.find('.//company').text
author = root.find('.//Author').text
OTHER TIPS
Try this.
from xml.etree import ElementTree as ET
xmlFile = ET.iterparse(open('some_file.xml','r'))
for tag, value in xmlFile:
print value.text