[英]Printing XML into HTML with python
I have a TextEdit widget in PyQt that I use to print out a log in HTML. 我在PyQt中有一个TextEdit小部件,用于打印HTML中的日志。 I use HTML so I can separate entries into color categories (red for error, yellow for debug, blue for message, etc), but this creates a problem.
我使用HTML,因此可以将条目分为颜色类别(红色表示错误,黄色表示调试,蓝色表示消息等),但这会造成问题。 Most of the debug messages are XML.
大多数调试消息是XML。 When I use appendHtml on the widget, it strips out all the tags.
当我在小部件上使用appendHtml时,它将剥离所有标签。
How can I pretty print XML in an HTML document? 如何在HTML文档中打印XML?
cgi.escape
can help you. cgi.escape
可以为您提供帮助。 It will convert the characters '&'
, '<'
and '>'
in the string to HTML-safe sequences. 它将字符串中的字符
'&'
, '<'
和'>'
为HTML安全序列。 That is enough to prevent interpretation of xml tags. 这足以防止解释xml标记。
>>> cgi.escape('<tag>')
'<tag>
A cdata section might help. cdata节可能会有所帮助。
http://reference.sitepoint.com/javascript/CDATASection http://reference.sitepoint.com/javascript/CDATASection
http://en.wikipedia.org/wiki/CDATA http://en.wikipedia.org/wiki/CDATA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.