XML Parsing

Konstantin Veretennicov kveretennicov at gmail.com
Tue Apr 1 22:01:39 CEST 2008


On Tue, Apr 1, 2008 at 10:42 PM, Alok Kothari <kothari.alok at gmail.com>
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 = """<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>"""
>

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 <module>
>    p.Parse(document, 1)
> ExpatError: junk after document element: line 1, column 33
>

Told ya :)


Try wrapping your document in root element, like
"<tokens><token>...</token><token>...</token></tokens>"

--
kv
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080401/c052fef8/attachment.html>


More information about the Python-list mailing list