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"tle\, v. t. [imp. & p. p. {Bristled}; p. pr. &
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 " and &. When reading with
if ( reader.isCharacters() )
qDebug() << reader.text().toString();
everything before the last such character (the second & 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 " and &. When reading with
>
> if ( reader.isCharacters() )
> qDebug() << reader.text().toString();
>
> everything before the last such character (the second & 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 ]