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. QXmlSchemaValidator - resolving xsd schemas locally
Qt 6.11 is out! See what's new in the release blog

QXmlSchemaValidator - resolving xsd schemas locally

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 410 Views 1 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.
  • K Offline
    K Offline
    kcris
    wrote on last edited by kcris
    #1

    Hi,

    I try to use QXmlSchemaValidator to validate an xml,
    and I want to resolve all schemas/xsds locally (I have to avoid using http to find the schemas, since I will work in offline mode).

    So what I did was to implement my own QAbstractUriResolver, something like this

    class MyUriResolver : public QAbstractUriResolver
    {
    public:
      MyUriResolver(QString baseLocalDir) : m_baseLocalDir{baseLocalDir}  {}
    
      QUrl resolve(const QUrl & relative, const QUrl & /*baseURI*/) const override
      {
        return QUrl::fromUserInput(m_baseLocalDir + relative.path());
      }
    
    private:
      QString m_baseLocalDir;
    };
    
    ... //then I use it like this:
    
    QXmlSchemaValidator validator(schema);
    
    MyUriResolver localUrlResolver{schemasLocalBaseDirAbsolute};
    validator.setUriResolver(&localUrlResolver);
    
    validator.validate(xmlText.toUtf8()); //does NEVER call MyUriResolver::resolve()
    

    My overridden MyUriResolver::resolve() above is never called. Any idea why?
    Thanks

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

      Hi,

      The code of the validator looks correct.

      Can you provide a minimal compilable example that uses it so that we can test it ?

      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