from lxml import etree XKML_NAME http www opengis net kml XKML_NAME2 h

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from lxml import etree
XKML_NAME="http://www.opengis.net/kml/2.2"
XKML_NAME2="http://www.google.com/kml/ext/2.2"
XKML_NAME3="http://www.opengis.net/kml/2.2"
XKML_NAME4="http://www.w3.org/2005/Atom"
NSMAP = {None : XKML_NAME, 'gx':XKML_NAME2, 'kml':XKML_NAME3, 'atom':XKML_NAME4}
kml=etree.Element("kml",nsmap=NSMAP)
root=etree.SubElement(kml,"root")
root.append( etree.Element("child1") )
child2=etree.SubElement(root,"child2")
child2.text="123"
print(etree.tostring(kml,encoding="UTF-8", xml_declaration=True, pretty_print=True))