This is a static archive of the Python wiki, which was retired in February 2026 due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

Learning python by example

Python XML & XSLT

Create and add elements

from xml.dom.minidom import parseString

doc = parseString(u'<top/>'.encode('UTF-8'))

<?xml version="1.0" ?>
<top/>

top_element=doc.documentElement

element1=doc.createElementNS(None,u'section1')

top_element.appendChild(element1)

element1.appendChild(doc.createElementNS(None,u'subsection1'))

text1=doc.createTextNode(u'My first text')

element1.firstChild.appendChild(text1)

element1.appendChild(doc.createElementNS(None,u'subsection2'))

text2=doc.createTextNode(u'My second text')
element1.lastChild.appendChild(text2)

element1.firstChild.appendChild(text2)
element1.lastChild.appendChild(text1)

2026-02-14 16:09