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

Ian Wadham ianw2 at optusnet.com.au
Thu Nov 30 07:22:25 CET 2006


Hi All,

I have been experimenting with a new game-file format for
KGoldrunner which will have all levels of one game in a
single text-file.  Using XML, my format is ...

<KGoldrunnerGame>
    <Header attribute= ...>description-text</Header>
    <Level N="001"><Layout>layout-codes</Layout>
        <Name>name-text</Name><Hint>hint-text</Hint>
    </Level>
    <Level N="002"> ... etc.

 </KGoldrunnerGame>

The problem is that "description-text", "name-text" and
"hint-text" could contain white space, multi-byte UTF-8
strings (such as "u" with umlaut) and rich-text formatting
tags such as <b>bold-text</b>, <em>emphasised</em>
or <p>paragraph-text</p>.  Some hints are several
paragraphs long ...

Using QDomDocument and QDomElement, it is fairly easy
to find a level by number and extract "layout-codes", "name-text"
and "hint-text", *but* it appears that QDomElement::text() is the
only function that gets the text between tag-pairs like <Hint> ...
</Hint> and it converts everything to a QString in Unicode.

What I really want is is a function which will give me all
the raw text as a QByteArray in its original UTF-8 encoding.
That is what I need to pass to the translators at build-time
and to the translation process "i18n()" at run time.

I can use QDomElement::text().toUtf8().  It gets back a "u"
with umlaut in 2 bytes as expected, but I am not sure I get
back all my whitespace and I certainly *lose* the format tags.

Is there some simple way to get back all my original text
without alterations?  Or should I abandon XML, use some
simple home-grown format and hand-code the parsing?  Or
maybe use KSimpleConfig?

Hoping someone can advise me,

Cheers, Ian W.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/kde-games-devel/attachments/20061130/1dbe043f/attachment.html 


More information about the kde-games-devel mailing list