I have a XML file:
<sentence id="en_BlueRibbonSushi_478218345:2">
<text>It has great sushi and even better service.</text>
</sentence>
<sentence id="en_BlueRibbonSushi_478218345:3">
<text>The entire staff was extremely accomodating and tended to my every need.</text>
</sentence>
<sentence id="en_BlueRibbonSushi_478218345:4">
<text>I've been to this restaurant over a dozen times with no complaints to date.</text>
</sentence>
Using XML ElementTree, I would like to insert a tag <Opinion>
that has an attribute category=
. Say I have a list of chars list = ['a', 'b', 'c']
, is it possible to incrementally asign them to each text so I have:
<sentence id="en_BlueRibbonSushi_478218345:2">
<text>It has great sushi and even better service.</text>
<Opinion category='a' />
</sentence>
<sentence id="en_BlueRibbonSushi_478218345:3">
<text>The entire staff was extremely accomodating and tended to my every need.</text>
<Opinion category='b' />
</sentence>
<sentence id="en_BlueRibbonSushi_478218345:4">
<text>I've been to this restaurant over a dozen times with no complaints to date.</text>
<Opinion category='c' />
</sentence>
I am aware I can use the sentence id attribute but this would require a lot of restructuring of my code. Basically, I'd like to be able to index each sentence entry to align with my list index.