[Qt-interest] XML encoding of UTF8

Atlant Schmidt aschmidt at dekaresearch.com
Wed Aug 18 21:57:17 CEST 2010


Jason:

  I don't see a Qt method that does conversion to HTML
  entities for more than the simple case of handling
  <, >, &, and ".

    QString Qt::escape ( const QString & plain )

      and its cousin

    QString Qt::convertFromPlainText ( const QString & plain,
                 WhiteSpaceMode mode = WhiteSpacePre )


  But it's not such an onerous task to walk through the
  QByteArray (or, more likely, the array converted to a
  Unicode QString) and when you see a character that needs
  encoding, encode that character and emit the resulting
  entity into the result string you're building or insert()
  the entity into the QByteArray, replacing and expanding
  the original character(s). (If you're doing many insert()s,
  that may be a slow operation.)

  And then file a JIRA with the Trolls asking that they
  provide a full-scale text encoder ;-).

  Or, just as likely, someone will point out where I missed
  the "obvious" class and method.

                         Atlant

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Jason H
Sent: Wednesday, August 18, 2010 14:22 PM
To: Jason H; qt-interest at trolltech.com
Subject: Re: [Qt-interest] XML encoding of UTF8

I need to "bump" this, and clarify.

My input has #233, my internal processing has it decoded, and my output, which
needs to be a QByteArray, needs to ahve it translated back to "&#233;"

Currently, it is being sent as 'é' (Actually a 2-byte char sequence). I want the
6 byte "&#233;" sequence in the output.

QDomDocument::toByteArray() is not doing it.





----- Original Message ----
From: Jason H <scorp1us at yahoo.com>
To: qt-interest at trolltech.com
Sent: Tue, August 17, 2010 12:45:19 PM
Subject: [Qt-interest] XML encoding of UTF8

I need to represent é (html: eacute, utf8: #233) in a QByteArray.

Here's what's happening. I get an XML/utf-8 file, read it, parse & modify it as
XML in QDomDocument, then I need to serialize it back out. When I do, I call
domDoc.toString().toUtf8().


But this leaves the raw UTF8 two-byte value in there. I need some way to have
the é re-encoded as é But not just that entity, all of them.

How/Does Qt do this?

Thanks!




_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest

This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.




More information about the Qt-interest-old mailing list