Created
July 27, 2018 12:09
-
-
Save Fhernd/5d032ffa195782f8135beb79f83d6d64 to your computer and use it in GitHub Desktop.
Leer, manipular y guardar un archivo XML. OrtizOL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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