Hello, 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 document = """<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 pos="np">Leno</token>""" # 3 handler functions def start_element(name, attrs): print 'Start element:', name, attrs def end_element(name): print 'End element:', name def char_data(data): print 'Character data:', repr(data) p = xml.parsers.expat.ParserCreate() p.StartElementHandler = start_element p.EndElementHandler = end_element p.CharacterDataHandler = char_data p.Parse(document, 1) OUTPUT: Start element: token {u'pos': u'nn'} Character data: u'Letterman' End element: token Traceback (most recent call last): File "C:/Python25/Programs/eg.py", line 20, in <module> p.Parse(document, 1) ExpatError: junk after document element: line 1, column 33 -- http://mail.python.org/mailman/listinfo/python-list