Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML parsing in python: expaterror not well-formed

I'm using Python's xml.etree.ElementTree to do some XML parsing on a file. However, I get this error mid-way through the document:

xml.parsers.expat.ExpatError: not well-formed (invalid token): line X, column Y

So I go to line X, column Y in vim and I see an ampersand (&) with red background highlighting. What does this mean?

Also the two characters preceding it are >>, so maybe there's something special about >>&?

Anyone know how to fix this?

like image 495
JDS Avatar asked Jul 11 '12 23:07

JDS


1 Answers

The & is a special character in XML, used for character entities. If your XML has & sitting there by itself, not as part of an entity like & or ѐ or the like, then the XML is invalid.

like image 163
BrenBarn Avatar answered Oct 06 '22 13:10

BrenBarn