[Kde-games-devel] Parsing and translating XML game-data

Ian Wadham ianw2 at optusnet.com.au
Sat Dec 2 14:10:59 CET 2006


2006/12/1, Ian Wadham wrote:
> > Burkhard, it is "QDomElement::text()" that drops lower-level
> > tags (as documented), not ".toUtf8()".  They never get into the
> > QString that QDomElement generates.
Burkhard Lehner wrote:
> Ah, I see the point! You have no way to store the characters '>'
> and '<' within XML text. But I thought these characters can be
> escaped with "&gt;" and "&lt;", or am I wrong here? Sorry, I'm
> not an XML expert, but at least HTML does it that way.
> 
Um, no ... a QString can have "rich text" in it, which is a subset
of HTML but also looks like the inner levels of some XML docs.
See Qt 4.2 doc home page and follow the path "Key Technologies,
Rich Text Processing, Supported HTML Subset".

For example, in my game-data in XML I might write:

<Hint>Do <b>not</b> go up the right hand ladder.</Hint>

If I display the QString "Do <b>not</b> go up ..." in a QLabel or
message box, the word "not" appears in bold font.  But when
QDomDocument parses the XML it treats the "<b>not</b>" as an
inner-level XML node (a QDomElement).  If you ask for the text()
of the <Hint> element, Qt omits the <b> and </b>, so you lose the
bold font effect.  The alternatives are to parse the rich-text format
tags to the Nth degree, then reconstruct the <Hint> text, or do as
Josef and I have discussed --- to get a string with rich-text tags
included, use "hint_element.save (text_stream, 0);".

Actually, none of the KGoldrunner hints contain rich text at
present, but I am trying to provide for a future in which we make
our game messages look more interesting in style, as we are
doing at present with our graphics.

Hope that clears things up, Ian W.



More information about the kde-games-devel mailing list