Python XML escape 转义

Python XML escape  Python 专用于XML字符串转移的函数。

escape example

from xml.sax.saxutils import escape
escape("< & >")

output:	'&lt; &amp; &gt;'

quoteattr example

>>> from xml.sax.saxutils import quoteattr
>>>
>>> quoteattr("some value ' containing an apostrophe")
'"some value \' containing an apostrophe"'
>>> quoteattr('some value containing " a double-quote')
'\'some value containing " a double-quote\''
>>> quoteattr('value containing " a double-quote \' and an apostrophe')
'"value containing " a double-quote \' and an apostrophe"'



你可能感兴趣的:(Python XML escape 转义)