Your search query "linkto%253A%2522LearnPython%2522" didn't return any results. Please change some terms and refer to HelpOnSearching for more information.
(!) Consider performing a full-text search with your search terms.

Clear message

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)

Unable to edit the page? See the FrontPage for instructions.