PDA

View Full Version : XML parsing problem using SAX2



Shawn
13th June 2007, 08:50
I'm want to parse a xml file twice or more times.
So I do it like this:

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

w = new test();
w->show();

QFile file("Resources/substations.xml");
QXmlInputSource inputSource(&file);

QXmlSimpleReader reader1, reader2;
Paser1 handler1;
reader1.setContentHandler(&handler1);
reader1.setErrorHandler(&handler1);
reader1.parse(inputSource);

Paser2 handler2;
handler2.num_Vol = handler1.num_Vol;
handler2.num_Trans = handler1.num_Trans;
handler2.num_Bay = handler1.num_Bay;
reader2.setContentHandler(&handler2);
reader2.setErrorHandler(&handler2);
reader2.parse(inputSource);

a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}

the error info: Parser error at line 1, column 1: unexpected end of file.
why? because the first time parsing reader1.parse(inputSource) seems OK, and that the 2 handler handle the same xml file.

any help would be appreciated.

jpn
13th June 2007, 09:15
Try calling QXmlInputSource::reset().

Shawn
13th June 2007, 10:04
I called file.seek(0) and it's OK:D
Any way, Thanks!

jpn
13th June 2007, 11:57
I called file.seek(0) and it's OK:D
I think QXmlInputSource::reset() would have done it "transparently" for you. ;)

Shawn
14th June 2007, 13:06
hehe, Thank u very much~