Hi folks,

I'm wanting to validate some XML with QXmlSchemaValidator, but I want it to use local copies of the schema files. I'm doing this:

  std::string xml = read_file();

  CustomResolver r;
  QXmlSchemaValidator v;
  v.setUriResolver(&r);

  QByteArray raw_data(s.c_str(), s.size());

  bool valid = v.validate(raw_data);

This is working. It's validating against the schema file(s) in the input document and returning true or false currectly on success or error. However... it's not calling the resolve() function in the URI resolver, so I can't map these schema URIs to local files. So every invocation requires network activity and is quite slow.

Is this the intended purpose of setUriResolver()? Should this be expected to work?

I also tried "v.schema().setUriResolver(&r);" since I saw this also had an option for setting a URI resolver, but this has no effect.

Is there a way of achieving this? With Xerces-C++, I was using a custom EntityResolver for this purpose, which worked perfectly to search a local tree of XML catalogue files. I want to achieve the equivalent behaviour with QtXmlPatterns/QtXml.

My resolve() function is currently a no-op:

  QUrl
  CustomResolver::resolve(const QUrl &relative,
                          const QUrl &baseURI) const
  {
    std::cerr << "QT resolve URI: rel="
              << relative.toString().toStdString() << " base="
              << baseURI.toString().toStdString() << std::endl;
    return baseURI.resolved(relative);
  }

I never see any output, so I'm fairly confident it's not being called.


Thanks,
Roger
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to