Qt 6.11 is out! See what's new in the release
blog
QXmlSchemaValidator - resolving xsd schemas locally
-
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 -
Hi,
The code of the validator looks correct.
Can you provide a minimal compilable example that uses it so that we can test it ?