Please nominate your Qt Champions for 2021!

Error when using QXmlSchema and QXmlSchemaValidator

  • Hello,

    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="">
      <xs:element type="xs:string" name="toto">

    And my XML file to validate :

    <?xml version="1.0" encoding="UTF-8" ?>

    When I try to validate this couple of files using other validation tools (for example, it is a success.

    But when I run this Qt code, I have an error :
    Error XSDError in file:ArchiverConfiguration.xml, at line 2, column 6: No definition for element toto available.

    bool isConfigurationFileValidAgainstSchema(const QString &filePath)
        // Retrieve the schema :
        QXmlSchema schema;
        // The xsd resource file can't be invalid :
        assert(schema.isValid() && "The  file schema (.xsd) is invalid.");
        // Validate the user file :
        QFile file{filePath};;
        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,

  • Lifetime Qt Champion


    Are you running a debug or release version of your application ? If a release then your assert won't help diagnosing if something's wrong.

  • Hi, I think you're right. I'm in a release version. And indeed my schema seems to be invalid. Thanks.

  • Lifetime Qt Champion

    You're welcome !

    Once you have your schema fixed, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

Log in to reply