Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error when using QXmlSchema and QXmlSchemaValidator
Forum Updated to NodeBB v4.3 + New Features

Error when using QXmlSchema and QXmlSchemaValidator

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Ben35
    wrote on last edited by
    #1

    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="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 file:ArchiverConfiguration.xml, at line 2, column 6: No definition for element toto available.

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • B Offline
        B Offline
        Ben35
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved