Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 27, 2018 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/5d032ffa195782f8135beb79f83d6d64 to your computer and use it in GitHub Desktop.
Save Fhernd/5d032ffa195782f8135beb79f83d6d64 to your computer and use it in GitHub Desktop.
Leer, manipular y guardar un archivo XML. OrtizOL.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment