bool MMLReader::parse(const QXmlInputSource &in) { QXmlSimpleReader p; // if the previous document was not retrieved, delete it if (doc) { delete doc; } doc = new MMLDocument(); contentHandler->setDocument(doc); p.setContentHandler(contentHandler); p.setErrorHandler(errorHandler); p.setEntityResolver(entityResolver); return p.parse(in); }
TestSuite *TestSuite::openCatalog(QIODevice *input, QString &errorMsg, const QUrl &fileName, const bool useExclusionList, SuiteType suiteType) { Q_ASSERT(input); QXmlSimpleReader reader; typedef QPatternist::AutoPtr<QXmlDefaultHandler> HandlerPtr; HandlerPtr loader; switch (suiteType) { case XQuerySuite: loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList)); break; case XsltSuite: loader = HandlerPtr(new XSLTTestSuiteHandler(fileName)); break; case XsdSuite: loader = HandlerPtr(new XSDTestSuiteHandler(fileName)); break; default: Q_ASSERT(false); break; } reader.setContentHandler(loader.data()); reader.setEntityResolver(loader.data()); QXmlInputSource source(input); if(!reader.parse(source)) { errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString()); return 0; } TestSuite *suite = 0; switch (suiteType) { case XQuerySuite: suite = static_cast<TestSuiteHandler *>(loader.data())->testSuite(); break; case XsltSuite: suite = static_cast<XSLTTestSuiteHandler *>(loader.data())->testSuite(); break; case XsdSuite: suite = static_cast<XSDTestSuiteHandler *>(loader.data())->testSuite(); break; default: Q_ASSERT(false); break; } if(suite) return suite; errorMsg = QString::fromLatin1("Failed to load \"%1\". " "It appears to have no test-suite element.\n").arg(fileName.toString()); return 0; }