XML expat error

dirkheld dirkheld at gmail.com
Wed Feb 27 17:02:25 EST 2008


On 27 feb, 17:18, "Richard Brodie" <R.Bro... at rl.ac.uk> wrote:
> "dirkheld" <dirkh... at gmail.com> wrote in message
>
> news:babb6775-311d-4f7a-bc03-90f249e34180 at s19g2000prg.googlegroups.com...
>
> > xml.parsers.expat.ExpatError: not well-formed (invalid token): line
> > 554, column 20
>
> > I guess that the element I try to read or the XML(which would be
> > strange since they have been created with the same code) can't ben
> > retrieved.
>
> It's fairly easy to write non-robust XML generating code, and also
> quick to test if one file is always bad. Drop it into a text editor or
> Firefox, and take a quick look at line 554. Most likely some random
> control character has sneaked in; it only takes (for example) one NUL
> to make the document ill-formed.

Something strange here. The xml file causing the problem has only 361
lines. Isn't there a way to catch this error, ignore it and continu
with the rest of the other files?
This is the full error report :

Traceback (most recent call last):
  File "xmltest.py", line 10, in <module>
    xmldoc = minidom.parse('/Documents/programming/data/xml/'+file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/xml/dom/minidom.py", line 1913, in parse
    return expatbuilder.parse(file)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/xml/dom/expatbuilder.py", line 924, in parse
    result = builder.parseFile(fp)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/xml/dom/expatbuilder.py", line 207, in parseFile
    parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line
554, column 20



More information about the Python-list mailing list