So, the way to look at this is that “I WANT IT” is actually another node. This is a text child of "data."
from xml.dom.minidom import parseString dom = parseString(data) nodes = dom.getElementsByTagName('data')
At this point, the "nodes" are a NodeList, and in your example it has one element in it, which is the "data" element. Accordingly, the "data" element also has only one child element, which is the text node "I WANT IT".
So you can just do something like this:
print nodes[0].firstChild.nodeValue
Please note that if there is more than one tag called “data” in your input, you should use some kind of iteration method on the “nodes”, and not index it directly.
source share