How validate with qt a xml file with xsd file which imports another xsd file?



I use this code to validate my foo.xml




QFile* fileXsd = new QFile("D:\\...\\fooValidator.xsd");
if (!fileXsd->open(QIODevice::ReadOnly | QIODevice::Text))
qWarning() << QObject::tr("Couldn't open xsd file.");
QXmlSchema schema;
schema.load(fileXsd);
if(schema.isValid())
{
QFile* fileXml = new QFile("D:\\...\\foo.xml");
if (!fileXml->open(QIODevice::ReadOnly | QIODevice::Text))
qWarning() << QObject::tr("Couldn't open xml file.");
QXmlSchemaValidator validator(schema);
if(!validator.validate(fileXml, QUrl::fromLocalFile(fileXml->fileName())))
qCritical() << "instance document is invalid";
else
{
//Ok
}
}


My file fooValidator.xsd imports types from a file fooTypeValidator.xsd.


fooValidator.xsd, fooTypeValidator.xsd and foo.xml are correct (I verrified with xmlvalidation)


When I run my program, I get an error ; the type declared in fooTypeValidator.xsd cannot be resolved.


fooTypeValidator.xsd is not imported by QXmlSchema nor by QXmlSchemaValidator


No comments:

Post a Comment