ElementTree's .write() changes strings with " to "

纵然是瞬间 提交于 2021-01-29 08:37:22

问题


In my code, I am changing an existed formatted string in XML with predefined format with ElementTree in Python.

<Value xsi:type='xs:string'>{&quot;name&quot;:&quot;Test123&quot;,&quot;type&quot;:&quot;}</Value>

New text adding by: ValueNode.text = '{&quot;name&quot;:&quot;NewTextdemo&quot;}'

and to save the file I am using doc.write(path_to_XML_file)

The problem is, that the doc.write(path_to_XML_file) is changing the &quot; to &amp;quot; further entity name - and so the result XML is invalid.

Does anybody know how to avoid it? How to set write function to omits conding these special characters?

Thank you

来源:https://stackoverflow.com/questions/61019991/elementtrees-write-changes-strings-with-quot-to-ampquot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!