directedition
directedition

Reputation: 11715

Printing XML into HTML with python

I have a TextEdit widget in PyQt that I use to print out a log in 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. Most of the debug messages are XML. When I use appendHtml on the widget, it strips out all the tags.

How can I pretty print XML in an HTML document?

Upvotes: 0

Views: 509

Answers (2)

nosklo
nosklo

Reputation: 223172

cgi.escape can help you. It will convert the characters '&', '<' and '>' in the string to HTML-safe sequences. That is enough to prevent interpretation of xml tags.

>>> cgi.escape('<tag>')
'&lt;tag&gt;

Upvotes: 4

Related Questions