本文整理汇总了C++中QXmlSchema::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlSchema::isValid方法的具体用法?C++ QXmlSchema::isValid怎么用?C++ QXmlSchema::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlSchema
的用法示例。
在下文中一共展示了QXmlSchema::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: languageSchemeValidationTest
void TestLanguageFiles::languageSchemeValidationTest()
{
QUrl languageFile = QUrl::fromLocalFile("schemes/language.xsd");
QXmlSchema languageSchema;
QVERIFY(languageSchema.load(languageFile));
QVERIFY(languageSchema.isValid());
}
示例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: 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: copyConstructor
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());
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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());
}
示例8: 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();
}
示例9: 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]
}
示例10: root
QObject * LanguageResource::resource()
{
if (d->m_languageResource != 0) {
return d->m_languageResource;
}
if (!d->m_path.isLocalFile()) {
qWarning() << "Cannot open language file at " << d->m_path.toLocalFile() << ", aborting.";
return 0;
}
QXmlSchema schema = loadXmlSchema("language");
if (!schema.isValid()) {
return 0;
}
QDomDocument document = loadDomDocument(d->m_path, schema);
if (document.isNull()) {
qWarning() << "Could not parse document " << d->m_path.toLocalFile() << ", aborting.";
return 0;
}
QDomElement root(document.documentElement());
d->m_languageResource = new Language(this);
d->m_languageResource->setFile(d->m_path);
d->m_languageResource->setId(root.firstChildElement("id").text());
d->m_languageResource->setTitle(root.firstChildElement("title").text());
d->m_languageResource->seti18nTitle(root.firstChildElement("i18nTitle").text());
// create phoneme groups
for (QDomElement groupNode = root.firstChildElement("phonemeGroups").firstChildElement();
!groupNode.isNull();
groupNode = groupNode.nextSiblingElement())
{
PhonemeGroup *group = d->m_languageResource->addPhonemeGroup(
groupNode.firstChildElement("id").text(),
groupNode.firstChildElement("title").text());
group->setDescription(groupNode.attribute("description"));
// register phonemes
for (QDomElement phonemeNode = groupNode.firstChildElement("phonemes").firstChildElement();
!phonemeNode.isNull();
phonemeNode = phonemeNode.nextSiblingElement())
{
group->addPhoneme(phonemeNode.firstChildElement("id").text(), phonemeNode.firstChildElement("title").text());
}
}
return d->m_languageResource;
}
示例11: 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();
}
示例12: validateActionDef
void cActionDefList::validateActionDef( const QString &p_qsActionDefFile, const QString &p_qsSchemaFile ) throw( cSevException )
{
cTracer obTracer( &g_obLogger, "cActionList::validateActionDef", p_qsActionDefFile.toStdString() );
QFile obActionsFile( p_qsActionDefFile );
try
{
if( !obActionsFile.open( QIODevice::ReadOnly ) )
{
throw cSevException( cSeverity::ERROR, QString( "Cannot open Actions file: %1" ).arg( p_qsActionDefFile ).toStdString() );
}
QXmlSchema obSchema;
obSchema.load( p_qsSchemaFile );
if( !obSchema.isValid() )
{
throw cSevException( cSeverity::ERROR, QString( "Schema %1 is not valid" ).arg( p_qsSchemaFile ).toStdString() );
}
QXmlSchemaValidator obValidator( obSchema );
if( !obValidator.validate( &obActionsFile, QUrl::fromLocalFile( p_qsActionDefFile ) ) )
{
throw cSevException( cSeverity::ERROR,
QString( "Action definition file %1 is not valid according to Schema %2" ).arg( p_qsActionDefFile ).arg( p_qsSchemaFile ).toStdString() );
}
QString qsErrorMsg = "";
int inErrorLine = 0;
obActionsFile.seek( 0 );
if( !m_poActionsDoc->setContent( &obActionsFile, &qsErrorMsg, &inErrorLine ) )
{
throw cSevException( cSeverity::ERROR,
QString( "Parsing Actions file: %1 - Error in line %2: %3" ).arg( p_qsActionDefFile ).arg( inErrorLine ).arg( qsErrorMsg ).toStdString() );
}
obActionsFile.close();
}
catch( cSevException &e )
{
obActionsFile.close();
throw e;
}
}
示例13: 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);
}
}
}
示例14: loadFromData
void Schema::loadFromData() const
{
//! [2]
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;
schema.load(data);
if (schema.isValid())
qDebug() << "schema is valid";
else
qDebug() << "schema is invalid";
//! [2]
}
示例15: 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");
}
}