python - Parsing xml with simple structure -
for reasons can't extract content of xml below: can please point me in right direction?
f='''<features> <name>michael</name> <age>81</age> <dob>20/10/1925</dob> </features>'''
attempt:
tree=et.parse(stringio(f)) root=tree.getroot() x in root: print x.tag, x.attrib output: name {} age {} dob {}
ideal output:
name {michael} age {81} dob {20/10/1925}
not @ xml python, suggestions?
your elements not have attrib
s. try x.text
instead, although need add curly braces if want text in curly braces.
>>> import xml.etree.celementtree et >>> root = et.fromstring(f) >>> x in root: print x.tag, x.text name michael age 81 dob 20/10/1925
Comments
Post a Comment