XML toprettyxml转义引号

时间:2016-12-14 15:05:22

标签: android python xml escaping

在Android字符串文档中,您可以看到此示例(重点是,如果您在字符串周围有双引号,则不需要转义单引号)。

<string name="good_example_2">"This'll also work"</string>

如果我想用python生成strings.xml,那么一切正常(预期的结果),直到我使用toprettyxml,这将把它变成

<string name="good_example_2">&quot;This'll also work&quot;</string>

我正在使用美化like in this example

from xml.etree import ElementTree
from xml.dom import minidom

def prettify(elem):
    """Return a pretty-printed XML string for the Element.
    """
    rough_string = ElementTree.tostring(elem, 'utf-8')
    reparsed = minidom.parseString(rough_string)
    return reparsed.toprettyxml(indent="  ")

toprettyxml转义引号。有什么方法可以阻止这种情况发生吗?

0 个答案:

没有答案