[kde-edu]: QDom/XML-Problem

Kevin Krammer kevin.krammer at gmx.at
Fri May 20 17:30:46 CEST 2005


On Friday 20 May 2005 17:19, Carsten Niehaus wrote:
> Hello
>
> I have code like this:  <desc>This is a picture.<img src="e.png" /> do you
> like it?</desc>
>
> I have <desc> as a QDomElement. No Problem. I need a QString from that
> element that looks like this:
>
> "This is a picture: <img src="/usr/share/kde/kalzium/data/e.png" /> do you
> like it?
>
> I am parsing xml to generate html from it but of course every system has a
> different &PATH for the pictures.
>
> My problem is: How do I write the filename (inclusive the correct path) at
> the correct position in the QString? It is easy to get the text of <desc>
> and the value of <img src="" />, only the position is my problem.

Maybe it would be better to have a placeholder for the image and specfic the 
image as a separate element or at the end of <desc> element.

For example
<item>
    <desc> this is a picture %0. Do you like it?</desc>
    <img src="..." />
</item>

This way the string is easily replacable for example in translations.
In the code you just take the text and substitute the image tag with 
QString::arg

QString text = desc.arg(imagetag);

Cheers,
Kevin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-edu/attachments/20050520/0dabec99/attachment.pgp


More information about the kde-edu mailing list