本文整理汇总了C++中QXmlSchema类的典型用法代码示例。如果您正苦于以下问题:C++ QXmlSchema类的具体用法?C++ QXmlSchema怎么用?C++ QXmlSchema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QXmlSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: languageSchemeValidationTest
void TestLanguageFiles::languageSchemeValidationTest()
{
QUrl languageFile = QUrl::fromLocalFile("schemes/language.xsd");
QXmlSchema languageSchema;
QVERIFY(languageSchema.load(languageFile));
QVERIFY(languageSchema.isValid());
}
示例2: 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();
}
示例3: schema2
void tst_QXmlSchema::copyConstructor() const
{
/* Verify that we can take a const reference, and simply do a copy of a default constructed object. */
{
const QXmlSchema schema1;
QXmlSchema schema2(schema1);
}
/* Copy twice. */
{
const QXmlSchema schema1;
QXmlSchema schema2(schema1);
QXmlSchema schema3(schema2);
}
/* Verify that copying default values works. */
{
const QXmlSchema schema1;
const QXmlSchema schema2(schema1);
QCOMPARE(schema2.messageHandler(), schema1.messageHandler());
QCOMPARE(schema2.uriResolver(), schema1.uriResolver());
QCOMPARE(schema2.networkAccessManager(), schema1.networkAccessManager());
QCOMPARE(schema2.isValid(), schema1.isValid());
}
}
示例4: url
void tst_QXmlSchema::loadSchemaUrlFail() const
{
const QUrl url("http://notavailable/");
QXmlSchema schema;
QVERIFY(!schema.load(url));
}
示例5: validator
//! [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);
}
示例6: validator
int XMLQtInterface::isValid() const
{
QXmlSchema schema;
if(_schemaName.length() > 0)
schema.load( QUrl::fromLocalFile((QString::fromStdString(_schemaName))) );
if ( schema.isValid() )
{
QXmlSchemaValidator validator( schema );
if ( validator.validate( _fileData ) )
return 1;
else
{
INFO("XMLQtInterface::isValid(): XML file %s is invalid (in reference to schema %s).",
_fileName.toStdString().c_str(), _schemaName.c_str());
}
}
else
{
// The following validator (without constructor arguments) automatically
// searches for the xsd given in the xml file.
QXmlSchemaValidator validator;
if ( validator.validate( _fileData ) )
return 1;
else
{
INFO("XMLQtInterface::isValid(): XML file %s is invalid (in reference to its schema).",
_fileName.toStdString().c_str());
}
}
return 0;
}
示例7: 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();
}
示例8: doValidate
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;
}
示例9: initMusicXmlSchema
static bool initMusicXmlSchema(QXmlSchema& schema)
{
// read the MusicXML schema from the application resources
QFile schemaFile(":/schema/musicxml.xsd");
if (!schemaFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug("initMusicXmlSchema() could not open resource musicxml.xsd");
MScore::lastError = QObject::tr("Internal error: Could not open resource musicxml.xsd\n");
return false;
}
// copy the schema into a QByteArray and fixup xs:imports,
// using a path to the application resources instead of to www.musicxml.org
// to prevent downloading from the net
QByteArray schemaBa;
QTextStream schemaStream(&schemaFile);
while (!schemaStream.atEnd()) {
QString line = schemaStream.readLine();
if (line.contains("xs:import"))
line.replace("http://www.musicxml.org/xsd", "qrc:///schema");
schemaBa += line.toUtf8();
schemaBa += "\n";
}
// load and validate the schema
schema.load(schemaBa);
if (!schema.isValid()) {
qDebug("initMusicXmlSchema() internal error: MusicXML schema is invalid");
MScore::lastError = QObject::tr("Internal error: MusicXML schema is invalid\n");
return false;
}
return true;
}
示例10: networkAccessManagerDefaultValue
void tst_QXmlSchema::networkAccessManagerDefaultValue() const
{
/* Test that the default value of network access manager is not empty. */
{
QXmlSchema schema;
QVERIFY(schema.networkAccessManager() != static_cast<QNetworkAccessManager*>(0));
}
}
示例11: networkAccessManagerSignature
void tst_QXmlSchema::networkAccessManagerSignature() const
{
/* Const object. */
const QXmlSchema schema;
/* The function should be const. */
schema.networkAccessManager();
}
示例12: loadSchemaDataFail
void tst_QXmlSchema::loadSchemaDataFail() const
{
// empty schema can not be loaded
const QByteArray data;
QXmlSchema schema;
QVERIFY(!schema.load(data));
}
示例13: messageHandlerDefaultValue
void tst_QXmlSchema::messageHandlerDefaultValue() const
{
/* Test that the default value of message handler is not empty. */
{
QXmlSchema schema;
QVERIFY(schema.messageHandler() != static_cast<QAbstractMessageHandler*>(0));
}
}
示例14: uriResolverDefaultValue
void tst_QXmlSchema::uriResolverDefaultValue() const
{
/* Test that the default value of uri resolver is empty. */
{
QXmlSchema schema;
QVERIFY(schema.uriResolver() == static_cast<QAbstractUriResolver*>(0));
}
}
示例15: messageHandlerSignature
void tst_QXmlSchema::messageHandlerSignature() const
{
/* Const object. */
const QXmlSchema schema;
/* The function should be const. */
schema.messageHandler();
}