How To Convert < Into < In Lxml, Python?
There's a xml file: I go to to to school. For some reason, I changed to &a
Solution 1:
First find a unescape
function:
from xml.sax.saxutils import unescape
entry=body[0]
unescape and replace it with the original:
body.replace(entry, e.fromstring(unescape(e.tounicode(entry))))
Solution 2:
If you know which element contains wrongly escaped elements:
# parse whole document as usual..
# find the entry element..
# parse the fragment
fragment = lxml.fromstring(entry.text)
# (optionally) add the fragment to the tree
entry.text = None
entry.append(fragment)
Post a Comment for "How To Convert < Into < In Lxml, Python?"