H
H
hatari2014-04-01 17:54:28
Python
hatari, 2014-04-01 17:54:28

How to insert a text value into an XML node using Python and xml.dom.minidom?

Hello.
I use xml.dom.minidom.
An xml element of the following type is selected:

>>> element = xml.getElementsByTagName('Description')[0]
>>> element
<DOM Element: Description at 0x2ed6468>
>>> element.toxml()
u'<Description/>'

please tell me how can i get this?
u'<Description>value</Description>'
Of all the possible (dir (element)) nothing fits, it turned out only to set the attribute:
>>> element.setAttribute('value','newAttr')
>>> element.toxml()
u'<Description value="newAttr"/>'

Thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Kuzmichev, 2014-04-01
@hatari

Strictly speaking, "just text" inside an element is a nested element, like a text node, this is how it should work:
element.appendChild(xml.createTextNode('value!'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question