Naf*_*Kay 8 python xml lxml cdata
我批量转换大量XML文件,将其字符编码更改为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)
Run Code Online (Sandbox Code Playgroud)
不幸的是,它正在摧毁我的CDATA部分而只是逃避它们.
来源:
<d><![CDATA[áÌÀøÅàùÑÄéú ëÌÄé áÈàÅùÑ éäå''ä ðÄùÑÀôÌÈè <small><small>(ùí ëå èæ)</small></small>
Run Code Online (Sandbox Code Playgroud)
目的地:
<d>????????? ??? ????? ???''? ??????? <small><small>(?? ?? ??)</small></small>
Run Code Online (Sandbox Code Playgroud)
有没有我可以设置的设置会告诉它单独留下我的CDATA部分?我主要使用LXML来更改字符编码并正确编写XML头.
unu*_*tbu 15
import lxml.etree as etree
parser = etree.XMLParser(strip_cdata=False)
with open(source_filename, "rb") as source:
tree = etree.parse(source, parser=parser)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2862 次 |
| 最近记录: |