get element text in DOM?

Uche Ogbuji uche at ogbuji.net
Fri Nov 12 17:47:25 EST 2004


Juliano Freitas <jubafre at atlas.ucpel.tche.br> wrote in message news:<mailman.6228.1100113797.5135.python-list at python.org>...
> 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

http://lists.fourthought.com/pipermail/4suite/2004-November/013027.html

Verbatim:

"""
Or, ObTopic, for 4Suite recent CVS:

>>> from Ft.Xml.Domlette import NonvalidatingReader
>>> doc = NonvalidatingReader.parseString("<root><teste> texto
</teste></root>", 'urn:dummy')
>>> print doc.xpath('string(/root/teste)')
 texto

Simple and sweet IMHO.
"""

-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
A hands-on introduction to ISO Schematron -
http://www-106.ibm.com/developerworks/edu/x-dw-xschematron-i.html
Schematron abstract patterns -
http://www.ibm.com/developerworks/xml/library/x-stron.html
Wrestling HTML (using Python) -
http://www.xml.com/pub/a/2004/09/08/pyxml.html
XML's growing pains - http://www.adtmag.com/article.asp?id=10196
XMLOpen and more XML Hacks -
http://www.ibm.com/developerworks/xml/library/x-think27.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/



More information about the Python-list mailing list