Fhernd icon

leer-manipular-guardar-xml.py

Fhernd | PRO | 07/27/18 12:08:59 PM UTC | 0 ⭐ | 3167 👁️ | Never ⏰ | []
Python |

420 B

|

None

|

0 👍

/

0 👎

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)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎