gpt4 book ai didi

python - Python 中的 XML 引用

转载 作者:数据小太阳 更新时间:2023-10-29 02:46:27 25 4
gpt4 key购买 nike

在python中如何引用XML来获取带有引用控制字符的字符串?

源字符串:

<root namespace="value" id="guid">
<child name="child1">Content</child>
</root>

结果字符串:

<root namespace=\"value\" id=\"guid\">\n    <child name=\"child1\">Content<\/child><\/root>

最佳答案

您可以在 python.org wiki 中找到有关如何转义/取消转义 xml 实体的信息。 .特别是,有一个关于使用 xml.sax.saxutils.quoteattr 引用属性的部分,这似乎是您要查找的内容。

关于python - Python 中的 XML 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6691996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com