本文整理汇总了C++中QXmlSchema::load方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlSchema::load方法的具体用法?C++ QXmlSchema::load怎么用?C++ QXmlSchema::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlSchema
的用法示例。
在下文中一共展示了QXmlSchema::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: isValid
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;
}
示例3: 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);
}
示例4: loadSchemaUrlFail
void tst_QXmlSchema::loadSchemaUrlFail() const
{
const QUrl url("http://notavailable/");
QXmlSchema schema;
QVERIFY(!schema.load(url));
}
示例5: languageSchemeValidationTest
void TestLanguageFiles::languageSchemeValidationTest()
{
QUrl languageFile = QUrl::fromLocalFile("schemes/language.xsd");
QXmlSchema languageSchema;
QVERIFY(languageSchema.load(languageFile));
QVERIFY(languageSchema.isValid());
}
示例6: 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();
}
示例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: loadSchemaDataFail
void tst_QXmlSchema::loadSchemaDataFail() const
{
// empty schema can not be loaded
const QByteArray data;
QXmlSchema schema;
QVERIFY(!schema.load(data));
}
示例9: loadXmlSchema
QXmlSchema TestLanguageFiles::loadXmlSchema(const QString &schemeName) const
{
QString relPath = QString("schemes/%1.xsd").arg(schemeName);
QUrl file = QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, relPath));
QXmlSchema schema;
if (schema.load(file) == false) {
qWarning() << "Schema at file " << file.toLocalFile() << " is invalid.";
}
return schema;
}
示例10: loadXmlSchema
QXmlSchema ResourceInterface::loadXmlSchema(const QString &schemeName) const
{
QString relPath = QString("schemes/%1.xsd").arg(schemeName);
QUrl file = QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, "artikulate/" + relPath));
QXmlSchema schema;
if (file.isEmpty() || schema.load(file) == false) {
qCWarning(ARTIKULATE_LOG) << "Schema at file " << file.toLocalFile() << " is invalid.";
}
return schema;
}
示例11: loadFromUrl
void Schema::loadFromUrl() const
{
//! [0]
QUrl url("http://www.schema-example.org/myschema.xsd");
QXmlSchema schema;
if (schema.load(url) == true)
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";
//! [0]
}
示例12: isValid
bool PairsTheme::isValid(const KArchiveFile* file) {
KUrl schemaUrl = KUrl::fromLocalFile(KGlobal::dirs()->findResource("appdata", QLatin1String( "themes/game.xsd" )));
QXmlSchema schema;
schema.load(schemaUrl);
if(!schema.isValid()) {
qWarning() << "game Schema not valid";
return false;
}
QXmlSchemaValidator validator(schema);
return validator.validate(file->data());
}
示例13: loadSchemaDataSuccess
void tst_QXmlSchema::loadSchemaDataSuccess() const
{
const QByteArray data( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<xsd:schema"
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
" xmlns=\"http://qt.nokia.com/xmlschematest\""
" targetNamespace=\"http://qt.nokia.com/xmlschematest\""
" version=\"1.0\""
" elementFormDefault=\"qualified\">"
"</xsd:schema>" );
QXmlSchema schema;
QVERIFY(schema.load(data));
}
示例14: 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();
}
示例15: loadFromFile
void Schema::loadFromFile() const
{
//! [1]
QFile file("myschema.xsd");
file.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&file, QUrl::fromLocalFile(file.fileName()));
if (schema.isValid())
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";
//! [1]
}