Hello Ian,<br><br><div><span class="gmail_quote">2006/12/2, Ian Wadham <<a href="mailto:ianw2@optusnet.com.au">ianw2@optusnet.com.au</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2006/12/1, Ian Wadham wrote:<br>> > Burkhard, it is "QDomElement::text()" that drops lower-level<br>> > tags (as documented), not ".toUtf8()". They never get into the<br>> > QString that QDomElement generates.
<br>Burkhard Lehner wrote:<br>> Ah, I see the point! You have no way to store the characters '>'<br>> and '<' within XML text. But I thought these characters can be<br>> escaped with "&gt;" and "&lt;", or am I wrong here? Sorry, I'm
<br>> not an XML expert, but at least HTML does it that way.<br>><br>Um, no ... a QString can have "rich text" in it, which is a subset<br>of HTML but also looks like the inner levels of some XML docs.<br>
See Qt 4.2 doc home page and follow the path "Key Technologies,<br>Rich Text Processing, Supported HTML Subset".<br><br>For example, in my game-data in XML I might write:<br><br><Hint>Do <b>not</b> go up the right hand ladder.</Hint>
<br><br>If I display the QString "Do <b>not</b> go up ..." in a QLabel or<br>message box, the word "not" appears in bold font. But when<br>QDomDocument parses the XML it treats the "<b>not</b>" as an
<br>inner-level XML node (a QDomElement). If you ask for the text()<br>of the <Hint> element, Qt omits the <b> and </b>, so you lose the<br>bold font effect.</blockquote><div><br>Why don't you just escape the special characters '<' and '>', so the rich text formatting tags no longer look like XML tags?
<br>So, your example would look like that:<br><Hint>Do &lt;b&gt;not&lt;/b&gt; go up the right hand ladder.</Hint><br><br>Now this is simple text, QDom* doesn't recognize any bold tags as XML tags, and converting it back is simply replacing every "&lt;" with '<' and every "&gt;" with '>'.
<br>Qt already has functions for doing the conversion in either direction. The function "escape" converts a string that contains rich text to a string that has all the characters '<', '>' and '&' escaped by "&lt;", "&gt;" and "&amp;" respectively. The function "convertFromPlainText" does the opposite and transforms the string back to rich text.
<br>In Qt 3.* these functions are static functions of the class "QStyleSheet", in Qt 4.* they are global functions in the namespace "Qt".<br><br>I hope this provides a solution to the problem.<br><br>Bye,
<br>Burkhard<br></div></div>