I have a huge list of different authors and their selected works in a <list>
in XML (namend bibliography.xml
). Here is an example:
<list type="index">
<item><persName>Poe, Edgar Allan</persName>, <note>1809—1849</note>, <bibl>The Black
Cat 1843 (<abbr>Cat.</abbr>).</bibl> — <bibl>The Gold-Bug 1843
(<abbr>Bug.</abbr>).</bibl> — <bibl>The Raven 1845
(<abbr>Rav.</abbr>).</bibl></item>
<item><persName>Melville, Herman</persName>, <bibl>Benito Cereno 1855
(<abbr>Ben.</abbr>)</bibl> — <bibl>Moby-Dick 1851
(<abbr>MobD.</abbr>)</bibl> — <bibl>Typee: A Peep at Polynesian Life 1846
(<abbr>PolyL.</abbr>)</bibl></item>
<item><persName>Barth, John</persName>, <note>(*1930)</note>, <bibl>The Sot-Weed
Factor 1960 (<abbr>Fac.</abbr>)</bibl> — <bibl>Giles Goat-Boy 1960
(<abbr>Gil.</abbr>)</bibl></item>
</list>
import xml.etree.ElementTree as ET
tree = ET.parse('bibliography.xml')
root = tree.getroot()
for work in root:
if(work.tag=='item'):
print work.get('persName')
if (attr.tag=='abbr')
print (attr.text)
obviously it's not working, but since I'm absolutely new to python, I can't wrap my mind around about what I'm doing wrong. Would be highly appreciated if someone could help me out here.
`, not the whole TEI-Header, body etc.
– SparrowSilencio Feb 27 '21 at 12:33