I receive xml strings from an external source that can contains unsanitized user contributed content.
The following xml string gave a ParseError in cElementTre
cElementTre
None of the above fixes worked for me. The only thing that worked was to use BeautifulSoup instead of ElementTree as follows:
BeautifulSoup
ElementTree
from bs4 import BeautifulSoup with open("data/myfile.xml") as fp: soup = BeautifulSoup(fp, 'xml')
Then you can search the tree as:
soup.find_all('mytag')