PyWombat

Crear archivos XML

Nuevo tip

La forma más sencilla de poder crear archivos .XML, es utilizando el módulo xml de Python.

Este módulo se encuentra en la biblioteca standard de Python, así que no hay necesidad de instalar absolutamente nada.

Ejemplo. Función que permite crear un XML a partir de un diccionario.

def dict_to_xml(tag, data):
    from xml.etree.ElementTree import Element
    from xml.etree.ElementTree import tostring

    element = Element(tag)

    for key, val in data.items():
        child = Element(key)
        child.text = str(val)

        element.append(child)

    return tostring(element).decode()