I batch convert many XML files, changing my character encodings to UTF-8:
with open(source_filename, "rb") as source: tree = etree.parse(source) with open(destination_filename, "wb") as destination: tree.write(destination, encoding="UTF-8", xml_declaration=True)
Unfortunately, it destroys my CDATA partitions and just eludes them.
A source
<d><![CDATA[áÌÀøÅàùÑÄéú ëÌÄé áÈàÅùÑ éäå''ä ðÄùÑÀôÌÈè <small><small>(ùí ëå èæ)</small></small>
Destination
<d>בְּרֵאשִׁית כִּי בָאֵשׁ יהו''ה נִשְׁפָּט <small><small>(שם כו טז)</small></small>
Is there a setting I can set that tells me that it will leave my CDATA sections alone? I mainly use LXML to change the character encoding and to spell the XML header correctly.
source share