<p>Here is my sample code:</p>

<pre><code>from xml.dom.minidom import *
def make_xml():
    doc = Document()
    node = doc.createElement('foo')
    node.innerText = 'bar'
    doc.appendChild(node)
    return doc
if __name__ == '__main__':
    make_xml().writexml(sys.stdout)
</code></pre>

<p>when I run the above code I get this:</p>

<pre><code>&lt;?xml version="1.0" ?&gt;
&lt;foo/&gt;
</code></pre>

<p>I would like to get:</p>

<pre><code>&lt;?xml version="1.0" ?&gt;
&lt;foo&gt;bar&lt;/foo&gt;
</code></pre>

<p>I just guessed that there was an innerText property, it gives no compiler error, but does not seem to work... how do I go about creating a text node?</p>

[{'answer_id': 29255, 'author': 'dF.', 'author_id': 3002, 'author_profile': 'https://Stackoverflow.com/users/3002', 'pm_score': 4, 'selected': True, 'text': '<p>Setting an attribute on an object won\'t give a compile-time or a run-time error, it will just do nothing useful if the object doesn\'t access it (i.e. "<code>node.noSuchAttr = \'bar\'</code>" would also not give an error).</p>\n\n<p>Unless you need a specific feature of <code>minidom</code>, I would look at <code>ElementTree</code>:</p>\n\n<pre><code>import sys\nfrom xml.etree.cElementTree import Element, ElementTree\n\ndef make_xml():\n    node = Element(\'foo\')\n    node.text = \'bar\'\n    doc = ElementTree(node)\n    return doc\n\nif __name__ == \'__main__\':\n    make_xml().write(sys.stdout)\n</code></pre>\n'}, {'answer_id': 29262, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 4, 'selected': False, 'text': "<p>@Daniel</p>\n\n<p>Thanks for the reply, I also figured out how to do it with the minidom (I'm not sure of the difference between the ElementTree vs the minidom)</p>\n\n<pre>\n<code>\nfrom xml.dom.minidom import *\ndef make_xml():\n    doc = Document();\n    node = doc.createElement('foo')\n    node.appendChild(doc.createTextNode('bar'))\n    doc.appendChild(node)\n    return doc\nif __name__ == '__main__':\n    make_xml().writexml(sys.stdout)\n</code>\n</pre>\n\n<p>I swear I tried this before posting my question...</p>\n"}]
['https://Stackoverflow.com/questions/29243', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1638/']