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

Qt-interest Archive, February 2008
Progress of SAX parser?


Message 1 in thread

Hi SAX parser users,

When working on a huge XML file parsing, a progress bar is quite helpful 
to indicate the percentage of finishing. I can initialize the progress 
range from 0 to the file size; problem is, from the reader, there no way 
to know how many bytes have been read and parsed. I wonder if there is a 
way to peek the progress of SAX parsing?

Thanks in advance,

Lingfa

--
 [ signature omitted ] 

Message 2 in thread

Lingfa Yang schrieb:
> Hi SAX parser users,
> 
> When working on a huge XML file parsing, a progress bar is quite helpful 
> to indicate the percentage of finishing. I can initialize the progress 
> range from 0 to the file size; problem is, from the reader, there no way 
> to know how many bytes have been read and parsed. I wonder if there is a 
> way to peek the progress of SAX parsing?

QXmlInputSource is your datasource, so you can get all your Information 
from there.

Stefan

--
 [ signature omitted ] 

Message 3 in thread

I would try gettig the file size and then monitoring how many bytes have been read.
That would feed the progress bar properly.
However, I saw nothing in QXmlInputSource that would help with that.

 -------------- Original message ----------------------
From: Weinzierl Stefan <Stefan@xxxxxxxxxxxxxxxxxxx>
> Lingfa Yang schrieb:
> > Hi SAX parser users,
> > 
> > When working on a huge XML file parsing, a progress bar is quite helpful 
> > to indicate the percentage of finishing. I can initialize the progress 
> > range from 0 to the file size; problem is, from the reader, there no way 
> > to know how many bytes have been read and parsed. I wonder if there is a 
> > way to peek the progress of SAX parsing?
> 
> QXmlInputSource is your datasource, so you can get all your Information 
> from there.
> 
> Stefan
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 4 in thread

ygor@xxxxxxxxxxx wrote:
> I would try gettig the file size and then monitoring how many bytes have been read.
> That would feed the progress bar properly.
> However, I saw nothing in QXmlInputSource that would help with that.
>
>   

Yes, that is exactly what I want the progress bar to be driven by.
I checked the handler (QXmlDefaultHandler), the reader 
(QXmlSimpleReader), and the source (QXmlInputSource). Unfortunately, 
none of them have capability to  monitoring the  bytes of processing.

Does anyone have insight on this issue?

Regards,
Lingfa

 

--
 [ signature omitted ] 

Message 5 in thread

On Mon February 4 2008 15:30, Lingfa Yang wrote:
> ygor@xxxxxxxxxxx wrote:
> > I would try gettig the file size and then monitoring how many bytes have
> > been read. That would feed the progress bar properly.
> > However, I saw nothing in QXmlInputSource that would help with that.
>
> Yes, that is exactly what I want the progress bar to be driven by.
> I checked the handler (QXmlDefaultHandler), the reader
> (QXmlSimpleReader), and the source (QXmlInputSource). Unfortunately,
> none of them have capability to  monitoring the  bytes of processing.
>
> Does anyone have insight on this issue?
Not me, I'm afraid...

But I once had a similar problem... if the input XML data describes many data 
objects of the same type (maybe with varying sub-tree structures), you could 
count the number of base objects parsed. But this requires that you somehow 
know about the total number _before_ you parse the data. In my case I was 
able to determine this in a different way. So perhaps that's also possible 
for you?!

HTH, René
-- 
 [ signature omitted ] 

Message 6 in thread

R. Reucher wrote:
> On Mon February 4 2008 15:30, Lingfa Yang wrote:
>   
>> ygor@xxxxxxxxxxx wrote:
>>     
>>> I would try gettig the file size and then monitoring how many bytes have
>>> been read. That would feed the progress bar properly.
>>> However, I saw nothing in QXmlInputSource that would help with that.
>>>       
>> Yes, that is exactly what I want the progress bar to be driven by.
>> I checked the handler (QXmlDefaultHandler), the reader
>> (QXmlSimpleReader), and the source (QXmlInputSource). Unfortunately,
>> none of them have capability to  monitoring the  bytes of processing.
>>
>> Does anyone have insight on this issue?
>>     
> Not me, I'm afraid...
>
> But I once had a similar problem... if the input XML data describes many data 
> objects of the same type (maybe with varying sub-tree structures), you could 
> count the number of base objects parsed. But this requires that you somehow 
> know about the total number _before_ you parse the data. In my case I was 
> able to determine this in a different way. So perhaps that's also possible 
> for you?!
>
> HTH, René
>   
Thank you sharing your experience. The tag counting in preprocessing 
returns total number of tags, and then, we can use it to set the range 
of the progress bar, and then ticks the bar in real processing. The 
drawback is cost of preprocessing - it sounds we have to parse the XML 
twice.

What I am using is a compromised solution. After statistics, I came up 
assuming 30 byes of content contains 1 tag, and every 1000 tags need 
updating the progress bar once. Inside startElement, I simply add:
    if(m_tagCount%1000 == 0)
        emit progressValue(m_tagCount*30); // signal
    ++m_tagCount;

Also, I received an alternative suggestion:
"QXmlStreamReader is a faster and more convenient replacement for Qt's 
own SAX parser (QXmlSimpleReader),
and it has a "characterOffset" method that should be exactly what is 
needed."
It sounds good.

Regards,
Lingfa

--
 [ signature omitted ]