I have a concern using the validation of an XML file with an XML Schema file. I tried to reproduce the basic sample provided by the documentation, but I have an error.
Here is my XML Schema :
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element type="xs:string" name="toto">
</xs:element>
</xs:schema>
And my XML file to validate :
<?xml version="1.0" encoding="UTF-8" ?>
<toto>titi</toto>
When I try to validate this couple of files using other validation tools (for example http://www.xmlvalidation.com/), it is a success.
But when I run this Qt code, I have an error :
Error XSDError in myFile.xml, at line 2, column 6: No definition for element toto available.
Code :
bool isConfigurationFileValidAgainstSchema(const QString &filePath)
{
// Retrieve the schema :
QXmlSchema schema;
schema.load(MY_XSD_URL);
// The xsd resource file can't be invalid :
assert(schema.isValid() && "The file schema (.xsd) is invalid.");
// Validate the user file :
QFile file{filePath};
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator{schema};
auto ok = validator.validate(&file, QUrl::fromLocalFile(file.fileName()));
return ok;
}
The error appears during the line :
auto ok = validator.validate(&file, QUrl::fromLocalFile(file.fileName()));
Would anyone have an idea of the problem?
Thank you, Ben