XML Parsing
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 = """LettermanisbetterthanJayLeno""" # 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 p.Parse(document, 1) ExpatError: junk after document element: line 1, column 33 -- http://mail.python.org/mailman/listinfo/python-list
Re: XML Parsing
Thanks ! it worked ! On Wed, Apr 2, 2008 at 1:31 AM, Konstantin Veretennicov < [EMAIL PROTECTED]> wrote: > On Tue, Apr 1, 2008 at 10:42 PM, Alok Kothari <[EMAIL PROTECTED]> > wrote: > > > 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 = """Lettermanis > token>betterthan > token>JayLeno""" > > > > This document is not well-formed. It doesn't have root element. > > ... > > > > > > Traceback (most recent call last): > > File "C:/Python25/Programs/eg.py", line 20, in > >p.Parse(document, 1) > > ExpatError: junk after document element: line 1, column 33 > > > > Told ya :) > > > Try wrapping your document in root element, like > ".." > > -- > kv > -- http://mail.python.org/mailman/listinfo/python-list