I'm want to parse a xml file twice or more times.
So I do it like this:
int main(int argc, char *argv[])
{
w = new test();
w->show();
QFile file("Resources/substations.xml");
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks