开发者

XML quoting in Python

开发者 https://www.devze.com 2023-03-20 01:44 出处:网络
How to quote XML to get the string with quoted control characters in python? Source string: <root namespace=\"value\" id=\"guid\">

How to quote XML to get the string with quoted control characters in python?

Source string:

<root namespace="value" id="guid">
    <chi开发者_如何学JAVAld name="child1">Content</child>
</root>

Result string:

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


You can find information about how to escape/unscape xml entities in the python.org wiki. In particular, there's a section about quoting attributes with xml.sax.saxutils.quoteattr which seems to be what you're looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号