Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.etree.ElementTree import parse, Element
- documento = parse('datos.xml')
- raiz = documento.getroot()
- print(raiz)
- # Remoción de elementos:
- raiz.remove(raiz.find('sri'))
- raiz.remove(raiz.find('cr'))
- # Inserción de un nuevo elemento:
- raiz.getchildren().index(raiz.find('nm'))
- e = Element('spam')
- e.text = 'Text, more text'
- raiz.insert(2, e)
- documento.write('datos-nuevos.xml', xml_declaration=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement