get element text in DOM?
Irmen de Jong
irmen at -nospam-remove-this-xs4all.nl
Wed Nov 10 15:12:23 EST 2004
Juliano Freitas wrote:
> How can i get the text between the <teste> tags??
>
>
>>>>xml = """<root><teste> texto </teste></root>"""
You must know that the text between the tags is a DOM element
by itself, namely a TEXT node, which is a child of the
elment node formed by the tag.
So try;
xml = """<root><teste> texto </teste></root>"""
from xml.dom import minidom
document = minidom.parseString(xml)
element = document.getElementsByTagName('teste')
textelt=element[0].firstChild
print textelt.nodeType, textelt.nodeValue
and it will print:
3 texto
--Irmen
More information about the Python-list
mailing list