本文整理汇总了C++中QXmlSchema::setMessageHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlSchema::setMessageHandler方法的具体用法?C++ QXmlSchema::setMessageHandler怎么用?C++ QXmlSchema::setMessageHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlSchema
的用法示例。
在下文中一共展示了QXmlSchema::setMessageHandler方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validator
static Score::FileError doValidate(const QString& name, QIODevice* dev)
{
QTime t;
t.start();
// initialize the schema
ValidatorMessageHandler messageHandler;
QXmlSchema schema;
schema.setMessageHandler(&messageHandler);
if (!initMusicXmlSchema(schema))
return Score::FileError::FILE_BAD_FORMAT; // appropriate error message has been printed by initMusicXmlSchema
// validate the data
QXmlSchemaValidator validator(schema);
bool valid = validator.validate(dev, QUrl::fromLocalFile(name));
qDebug("Validation time elapsed: %d ms", t.elapsed());
if (valid)
qDebug("importMusicXml() file '%s' is a valid MusicXML file", qPrintable(name));
else {
qDebug("importMusicXml() file '%s' is not a valid MusicXML file", qPrintable(name));
MScore::lastError = QObject::tr("File '%1' is not a valid MusicXML file").arg(name);
if (MScore::noGui)
return Score::FileError::FILE_NO_ERROR; // might as well try anyhow in converter mode
if (musicXMLValidationErrorDialog(MScore::lastError, messageHandler.getErrors()) != QMessageBox::Yes)
return Score::FileError::FILE_USER_ABORT;
}
// return OK
return Score::FileError::FILE_NO_ERROR;
}
示例2: validateXML
ErrorResult validateXML(const QString &fileName, const QString &schemaFileName)
{
QXmlSchema schema;
schema.load(QUrl(schemaFileName));
MessageHandler schemaMessageHandler;
schema.setMessageHandler(&schemaMessageHandler);
if (!schema.isValid())
return ErrorResult(ErrorResultType_Critical, QObject::tr("Schena '%1' is not valid. %2").
arg(schemaFileName).
arg(schemaMessageHandler.statusMessage()));
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
MessageHandler validatorMessageHandler;
validator.setMessageHandler(&validatorMessageHandler);
//TODO neslo mi nacist soubor se dvema poli
// if (!validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
// return ErrorResult(ErrorResultType_Critical, QObject::tr("File '%1' is not valid Agros2D problem file. Error (line %3, column %4): %2").
// arg(fileName).
// arg(validatorMessageHandler.statusMessage()).
// arg(validatorMessageHandler.line()).
// arg(validatorMessageHandler.column()));
return ErrorResult();
}
示例3: loadScene
Object* loadScene(const string& strFileName)
{
qDebug() << "Loading scene from file" << QString::fromStdString(strFileName);
QFile schemaFile(":/Schema/Schema/schema.xsd");
QXmlSchema schema;
WispMessageHandler handler;
schema.setMessageHandler(&handler);
if (!schemaFile.open(QIODevice::ReadOnly))
throw WispException(formatString("Unable to open the XML schema!"));
if (!schema.load(schemaFile.readAll()))
throw WispException(formatString("Unable to parse the XML schema!"));
QXmlSchemaValidator validator(schema);
QFile file(QString::fromStdString(strFileName));
if (!file.open(QIODevice::ReadOnly))
throw WispException(formatString("Unable to open the file \"%s\"", strFileName.c_str()));
if (!validator.validate(&file))
throw WispException(formatString("Unable to validate the file \"%s\"", strFileName.c_str()));
file.seek(0);
Parser parser;
QXmlSimpleReader reader;
reader.setContentHandler(&parser);
QXmlInputSource source(&file);
if (!reader.parse(source))
throw WispException(formatString("Unable to parse the file \"%s\"", strFileName.c_str()));
return parser.getRoot();
}
示例4: validate
//! [3]
void MainWindow::validate()
{
const QByteArray schemaData = schemaView->toPlainText().toUtf8();
const QByteArray instanceData = instanceEdit->toPlainText().toUtf8();
MessageHandler messageHandler;
QXmlSchema schema;
schema.setMessageHandler(&messageHandler);
schema.load(schemaData);
bool errorOccurred = false;
if (!schema.isValid()) {
errorOccurred = true;
} else {
QXmlSchemaValidator validator(schema);
if (!validator.validate(instanceData))
errorOccurred = true;
}
if (errorOccurred) {
validationStatus->setText(messageHandler.statusMessage());
moveCursor(messageHandler.line(), messageHandler.column());
} else {
validationStatus->setText(tr("validation successful"));
}
const QString styleSheet = QString("QLabel {background: %1; padding: 3px}")
.arg(errorOccurred ? QColor(Qt::red).lighter(160).name() :
QColor(Qt::green).lighter(160).name());
validationStatus->setStyleSheet(styleSheet);
}
示例5: messageHandler
void tst_QXmlSchema::messageHandler() const
{
/* Test that we return the message handler that was set. */
{
MessageSilencer handler;
QXmlSchema schema;
schema.setMessageHandler(&handler);
QCOMPARE(schema.messageHandler(), static_cast<QAbstractMessageHandler *>(&handler));
}
}
示例6: ouvrir
void Fenetre::ouvrir()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Séléctionner un fichier"),
QDir::currentPath(),
tr("Fichiers XML (*.xml)"));
if (fileName.isEmpty())
return;
QFile fileXML(fileName);
if (!fileXML.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Erreur lecture"),
tr("Impossible de lire le fichier %1:\n%2.")
.arg(fileName)
.arg(fileXML.errorString()));
return;
}
QFile fileSchema("schemaGraph.xsd");
fileSchema.open(QIODevice::ReadOnly);
QXmlSchema schema;
MessageHandler messageHandler;
schema.setMessageHandler(&messageHandler);
schema.load(&fileSchema, QUrl::fromLocalFile(fileSchema.fileName()));
if (schema.isValid()) {
QFile fileXML2(fileName);
fileXML2.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (!validator.validate(&fileXML2, QUrl::fromLocalFile(fileXML2.fileName()))){
QMessageBox::warning(this, tr("Fichier malformé"),
tr("Impossible d'ouvrir le fichier' %1'.\n Le document ne correspond pas au schéma. \n%2")
.arg(fileName)
.arg(messageHandler.statusMessage()));
return;
}
}
ImportExport import=ImportExport(&graphe,xmltree, affichageSVG);
if (import.ouvrir(&fileXML, &domDocument))
ui->statusBar->showMessage(tr("Fichier chargé"), 2000);
affichageSVG->drawGraph();
ui->afficheGraphe->adjustSize();
//On pense à remettre la liste des sommets pour créer les arcs
redessinerComboArc();
}
示例7: validator
MerDevicesXmlReader::MerDevicesXmlReader(const QString &fileName, QObject *parent)
: QObject(parent),
d(new MerDevicesXmlReaderPrivate)
{
Utils::FileReader reader;
d->error = !reader.fetch(fileName, QIODevice::ReadOnly);
if (d->error) {
d->errorString = reader.errorString();
return;
}
QXmlSchema schema;
schema.setMessageHandler(&d->messageHandler);
Utils::FileReader schemeReader;
d->error = !schemeReader.fetch(QString::fromLatin1("%1/mer/devices.xsd").arg(sharedDirPath()),
QIODevice::ReadOnly);
if (d->error) {
d->errorString = schemeReader.errorString();
return;
}
schema.load(schemeReader.data());
d->error = !schema.isValid();
if (d->error) {
d->errorString = d->messageHandler.errorString();
return;
}
QXmlSchemaValidator validator(schema);
validator.setMessageHandler(&d->messageHandler);
d->error = !validator.validate(reader.data());
if (d->error) {
d->errorString = d->messageHandler.errorString();
return;
}
d->query.setQuery(QString::fromLatin1("doc('%1')").arg(fileName));
d->query.setMessageHandler(&d->messageHandler);
d->error = !d->query.isValid();
if (d->error) {
d->errorString = d->messageHandler.errorString();
return;
}
d->error = !d->query.evaluateTo(d->receiver);
if (d->error)
d->errorString = d->messageHandler.errorString();
}
示例8: propertyInitialization
void tst_QXmlSchemaValidator::propertyInitialization() const
{
/* Verify that properties set in the schema are used as default values for the validator */
{
MessageSilencer handler;
TestURIResolver resolver;
QNetworkAccessManager manager;
QXmlSchema schema;
schema.setMessageHandler(&handler);
schema.setUriResolver(&resolver);
schema.setNetworkAccessManager(&manager);
QXmlSchemaValidator validator(schema);
QCOMPARE(validator.messageHandler(), static_cast<QAbstractMessageHandler *>(&handler));
QCOMPARE(validator.uriResolver(), static_cast<const QAbstractUriResolver *>(&resolver));
QCOMPARE(validator.networkAccessManager(), &manager);
}
}
示例9: validateInput
//----------------------------------------------------------------------------
bool ctkCmdLineModuleXmlValidator::validateInput()
{
d->ErrorStr.clear();
if (!d->Input)
{
d->ErrorStr = "No input set for validation.";
return false;
}
QIODevice* inputSchema = d->InputSchema;
QScopedPointer<QIODevice> defaultInputSchema(new QFile(":/ctkCmdLineModule.xsd"));
if (!inputSchema)
{
inputSchema = defaultInputSchema.data();
inputSchema->open(QIODevice::ReadOnly);
}
ctkCmdLineModuleXmlMsgHandler errorHandler;
QXmlSchema schema;
schema.setMessageHandler(&errorHandler);
if (!schema.load(inputSchema))
{
QString msg("Invalid input schema at line %1, column %2: %3");
d->ErrorStr = msg.arg(errorHandler.line()).arg(errorHandler.column()).arg(errorHandler.statusMessage());
return false;
}
QXmlSchemaValidator validator(schema);
if (!validator.validate(d->Input))
{
QString msg("Error validating CLI XML description, at line %1, column %2: %3");
d->ErrorStr = msg.arg(errorHandler.line()).arg(errorHandler.column())
.arg(errorHandler.statusMessage());
return false;
}
return true;
}
示例10: messageHandlerDefaultValue
void tst_QXmlSchemaValidator::messageHandlerDefaultValue() const
{
/* Test that the default value of message handler is equal to the one from the schema. */
{
const QXmlSchema schema;
const QXmlSchemaValidator validator(schema);
QVERIFY(validator.messageHandler() == schema.messageHandler());
}
/* Test that the default value of network access manager is equal to the one from the schema. */
{
QXmlSchema schema;
MessageSilencer handler;
schema.setMessageHandler(&handler);
const QXmlSchemaValidator validator(schema);
QVERIFY(validator.messageHandler() == schema.messageHandler());
}
}
示例11: parseMetaModelText
/*!
* \brief Utilities::parseMetaModelText
* Parses the MetaModel text against the schema.
* \param pMessageHandler
* \param contents
*/
void Utilities::parseMetaModelText(MessageHandler *pMessageHandler, QString contents)
{
QFile schemaFile(QString(":/Resources/XMLSchema/tlmModelDescription.xsd"));
schemaFile.open(QIODevice::ReadOnly);
const QString schemaText(QString::fromUtf8(schemaFile.readAll()));
schemaFile.close();
const QByteArray schemaData = schemaText.toUtf8();
QXmlSchema schema;
schema.setMessageHandler(pMessageHandler);
schema.load(schemaData);
if (!schema.isValid()) {
pMessageHandler->setFailed(true);
} else {
QXmlSchemaValidator validator(schema);
if (!validator.validate(contents.toUtf8())) {
pMessageHandler->setFailed(true);
}
}
}
示例12: executeSchemaTest
void XSDTSTestCase::executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler)
{
QFile file(m_schemaUri.path());
if (!file.open(QIODevice::ReadOnly)) {
resultStatus = TestResult::Fail;
serialized = QString();
return;
}
QXmlSchema schema;
schema.setMessageHandler(handler);
schema.load(&file, m_schemaUri);
if (schema.isValid()) {
resultStatus = TestResult::Pass;
serialized = QString::fromLatin1("true");
} else {
resultStatus = TestResult::Pass;
serialized = QString::fromLatin1("false");
}
}
示例13: executeInstanceTest
void XSDTSTestCase::executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler)
{
QFile instanceFile(m_instanceUri.path());
if (!instanceFile.open(QIODevice::ReadOnly)) {
resultStatus = TestResult::Fail;
serialized = QString();
return;
}
QXmlSchema schema;
if (m_schemaUri.isValid()) {
QFile file(m_schemaUri.path());
if (!file.open(QIODevice::ReadOnly)) {
resultStatus = TestResult::Fail;
serialized = QString();
return;
}
schema.setMessageHandler(handler);
schema.load(&file, m_schemaUri);
if (!schema.isValid()) {
resultStatus = TestResult::Pass;
serialized = QString::fromLatin1("false");
return;
}
}
QXmlSchemaValidator validator(schema);
validator.setMessageHandler(handler);
qDebug("check %s", qPrintable(m_instanceUri.path()));
if (validator.validate(&instanceFile, m_instanceUri)) {
resultStatus = TestResult::Pass;
serialized = QString::fromLatin1("true");
} else {
resultStatus = TestResult::Pass;
serialized = QString::fromLatin1("false");
}
}
示例14: validate
bool MainWindow::validate()
{
QUrl url("qrc:/resources/peach.xsd");
const QByteArray instanceData = completingTextEdit->toPlainText().toUtf8();
MessageHandler messageHandler;
QXmlSchema schema;
schema.setMessageHandler(&messageHandler);
schema.load(url);
bool errorOccurred = false;
if (!schema.isValid()) {
errorOccurred = true;
} else {
QXmlSchemaValidator validator(schema);
if (!validator.validate(instanceData))
errorOccurred = true;
}
if (errorOccurred) {
statusLabel->setText(messageHandler.statusMessage());
moveCursor(messageHandler.line(), messageHandler.column());
return false;
} else {
statusLabel->setText(tr("Validation successful"));
return true;
}
const QString styleSheet = QString("QstatusLabel {background: %1; padding: 3px}")
.arg(errorOccurred ? QColor(Qt::red).lighter(160).name() :
QColor(Qt::green).lighter(160).name());
statusLabel->setStyleSheet(styleSheet);
}