get element text in DOM?

Jeremy Jones zanesdad at bellsouth.net
Wed Nov 10 14:20:13 EST 2004


Sorry - my send finger got a little trigger happy.  Let's try again.

Jeremy Jones wrote:

> Juliano Freitas wrote:
>
>>How can i get the text between the <teste> tags??
>>
>>  
>>
>>>>>xml = """<root><teste> texto </teste></root>"""
>>>>>from xml.dom import minidom
>>>>>document = minidom.parseString(xml)
>>>>>document
>>>>>        
>>>>>
>><xml.dom.minidom.Document instance at 0x4181df0c>
>>  
>>
>>>>>minidom.getElementsByTagName('teste')
>>>>>        
>>>>>
>>
>>  
>>
>>>>>element = document.getElementsByTagName('teste')
>>>>>element
>>>>>        
>>>>>
>>[<DOM Element: teste at 0x418e110c>]
>>  
>>
>>>>>element[0].nodeType
>>>>>        
>>>>>
>>1
>>
>>Juliano Freitas
>>
>>
>>  
>>
> How about something like this:
>
>
>
In [24]: from xml.dom import minidom

In [25]: x = """<root><teste> texto </teste></root>"""

In [26]: document = minidom.parseString(x)

In [27]: print 
document.documentElement.getElementsByTagName('teste')[0].childNodes[0].data


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041110/3d33f85d/attachment.html>


More information about the Python-list mailing list