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

Qt-interest Archive, August 2007
QXmlStreamReader: parsing a file being streamed over a network


Message 1 in thread

Hi,

I'm slightly confused as to the best/intended way to parse an XML file
as it's being downloaded over a network using QXmlStreamReader.

I've subclassed QXmlStreamReader and I'm using KIO from KDE so
whenever I get a data(KIO::Job* kiojob,const QByteArray& data) signal
I do addData(data) in the corresponding slot.

I'm thinking my reader should look something like this:
<code>

void TestXmlStreamReaderDownloader::doRead()
{
  while (!atEnd()) {
    readNext();

    if(error() == PrematureEndOfDocumentError) {
      waitForMoreData();  // this is the issue
    }

    if (isStartElement()) {
      // random example XML parsing here
      if (name() == "xml" && attributes().value("version") == "1") {
        readXml();
    }
      else {
        raiseError("not valid xml");
      }
    }
  }
  if(error() == NoError) {
    emit finished();
  }
  else {
    emit failed();
  }
}

</code>

Any words of advice?

-- 
 [ signature omitted ] 

Message 2 in thread

On Wednesday 01 August 2007 07:16:16 pm Gavin Beatty wrote:
> Hi,
>
> I'm slightly confused as to the best/intended way to parse an XML file
> as it's being downloaded over a network using QXmlStreamReader.

[...]
>
>
> Any words of advice?


Have a look at the rsslisting example, it does exactly this.

Matthias

--
 [ signature omitted ] 

Message 3 in thread

On 02/08/07, Matthias Ettrich <ettrich@xxxxxxxxxxxxx> wrote:
> Have a look at the rsslisting example, it does exactly this.

I completely missed that fact. :-/
Pity about the example not having "context" in the XML ;)


Apologies and many thanks,
Gavin


-- 
 [ signature omitted ]