Generating xml in python and lxml

前端 未结 4 1022
逝去的感伤
逝去的感伤 2020-12-25 08:21

I have this xml from sql, and I want to do the same by python 2.7 and lxml



  

        
4条回答
  •  太阳男子
    2020-12-25 09:02

    Promoting my comment to an answer:

    @sukbir is probably not using Windows. What happens is that lxml writes a newline (0A 00 in UTF-16LE) between the XML header and the body. This is then molested by Win text mode to become 0D 0A 00 which makes everything after that look like UTF-16BE hence the Chinese etc characters when you display it. You can get around this in this instance by using "wb" instead of "w" when you open the file. However I'd strongly suggest that you use 'UTF-8' (spelled EXACTLY like that) as your encoding. Why are you using UTF-16? You like large files and/or weird problems?

提交回复
热议问题