Numbering the sentences inside a

in a .xml file?

后端 未结 1 1611
情话喂你
情话喂你 2021-01-24 05:37

I\'m a beginner programmer and I\'m stuck on this possibly easy problem: I want to automatically add numbers to the sentences contained in the P tags of an .xml file. So a sampl

相关标签:
1条回答
  • 2021-01-24 06:03

    Something like this (very untested) might work

    import xml.etree.ElementTree as ET
    tree = ET.parse(XML_FILE)
    root = tree.getroot()
    
    
    for p in root.iter('p'):
       sentences = p.text.split('.')
       p.text = ".".join([("<sup>%i<sup>" % count) + sentence for count, sentence in enumerate(sentences)])
    
    tree.write(XML_FILE)
    
    0 讨论(0)
提交回复
热议问题