XML Parsing

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Apr 2 02:45:31 CEST 2008

En Tue, 01 Apr 2008 20:44:41 -0300, 7stud <bbxx789_05ss at yahoo.com>  

>>           I am new to XML parsing.Could you kindly tell me whats the
>> problem with the following code:
>> import xml.dom.minidom
>> import xml.parsers.expat
> I don't know if you are aware of the BeautifulSoup module:
Or ElementTree:

import xml.etree.ElementTree as ET

doctext = """<tokens><token pos="nn">Letterman</token><token  
pos="bez">is</token><token pos="jjr">better</token><token  
pos="cs">than</token><token pos="np">Jay</token><token  

doc = ET.fromstring(doctext)
for token in doc.findall("token"):
    print 'pos:', token.get('pos')
    print 'text:', token.text

Gabriel Genellina

More information about the Python-list mailing list