Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, May 2007
Re: QXmlStreamReader


Message 1 in thread

Hi,

Tim Dewhirst wrote:
> Attached is a small example.

Thank you. That works very well. Except when the data read becomes more
complex, as in this real world example:

<ar><k>Bristle</k>
Bristle \Bris&quot;tle\, v. t. [imp. &amp; p. p. {Bristled}; p. pr. &amp;
vb.
   n. {Bristling}.]
   1. To erect the bristles of; to cause to stand up, as the
      bristles of an angry hog; -- sometimes with up.
      [1913 Webster]

            Now for the bare-picked bone of majesty
            Doth dogged war bristle his angry crest. --Shak.
      [1913 Webster]

            Boy, bristle thy courage up.          --Shak.
      [1913 Webster]

   2. To fix a bristle to; as, to bristle a thread.
      [1913 Webster]</ar>

As you can see the text contains &quot; and &amp;. When reading with 

if ( reader.isCharacters() )
   qDebug() << reader.text().toString();

everything before the last such character (the second &amp; in this case)
gets chopped of.

The above is from an xdxf version of an old edition of Webster's dictionary.
Since it has 200,655 entries, I was hoping that QXmlStreamReader would be
faster than QDomDocument, but that does not really seem to be the case.

Anyway, thanks again for your help.

Peter

--
 [ signature omitted ] 

Message 2 in thread

Hi,

Peter Hedlund wrote:
> As you can see the text contains &quot; and &amp;. When reading with 
> 
> if ( reader.isCharacters() )
>    qDebug() << reader.text().toString();
> 
> everything before the last such character (the second &amp; in this case)
> gets chopped of.

If you modify the code to look like:

QString data;
while ( !( reader.isEndElement() && reader.name() == "ar" ) )
{
     // should be two children
     reader.readNext();
     if ( reader.isStartElement() && reader.name() == "k" )
         qDebug() << reader.readElementText();
     else if ( reader.isCharacters() || reader.isEntityReference() )
         data += reader.text().toString();
}

qDebug() << data;

Then you'll see all of the data retrieved with the entities substituted.

Tim

--
 [ signature omitted ]