BuZZ-dEE BuZZ-dEE - 2 months ago 12
Python Question

How to set text into a DOM element

I'm trying to set text into a DOM element. I create the element.

svg_doc = minidom.parse('PATH_TO_SVG_FILE.svg')
category = svg_doc.createElement('category')


Then I try to set the
nodeValue
:

category.nodeValue = 'Design'


But I get:

<category/>


instead of:

<category>Design<category/>


How to get the desired result with minidom?

Answer

I think this should work:

category.createTextNode('Design')

See: https://docs.python.org/2/library/xml.dom.minidom.html