from xml.dom.minidom import parseString d = parseString("wibble") d.documentElement.appendChild(d.createComment("-->")) print d.toxml()