Hi :)

I'm trying to find a solution that in case that a validation is not successful because there is more then one error in the XML file the QT MessageHandler(line, column, description etc. ) is able to show every error in the XML data not just the first one that occurs in the XML file.

Example: I have an error in line: 65 (see pic)

ask.png

but there are also errors in line :78,83,95 but it dose not show it only shows the first one.

Is there a solution for this case? And if yes how?

My Code looks like this:


Qt Code:
  1. MessageHandler messageHandler;
  2. QFile xsdfile("....xsd");
  3. xsdfile.open(QIODevice::ReadOnly);
  4. QXmlSchema schema;
  5. schema.setMessageHandler(&messageHandler);
  6. bool errorOccurred = false;
  7. if (schema.load(&xsdfile, QUrl::fromLocalFile(xsdfile.fileName())) == false)
  8. errorOccurred = true;
  9. else
  10. {
  11. QXmlSchemaValidator xmlvalidator(schema);
  12.  
  13. QFile xmlfile("......xml");
  14. xmlfile.open(QIODevice::ReadOnly);
  15.  
  16. if (!xmlvalidator.validate(&xmlfile, QUrl::fromLocalFile(xmlfile.fileName())))
  17. errorOccurred = true;
  18.  
  19. xmlfile.close();
  20. }
  21. xsdfile.close();
  22. if (errorOccurred) {
  23. QString qs = messageHandler.statusMessage();
  24. cout << "Line: " << messageHandler.line() << "\n" << "Row: " << messageHandler.column() << "\n" << "ErrorMessage: ";
  25. std::cout << qs.toUtf8().constData() << std::endl;
  26. return -1;
  27. }
  28. else {
  29.  
  30. return 0;
  31. }
To copy to clipboard, switch view to plain text mode 



And my MessageHandler class looks like this:

Qt Code:
  1. class MessageHandler : public QAbstractMessageHandler
  2. {
  3. public:
  4. MessageHandler()
  5. : QAbstractMessageHandler(0)
  6. {
  7. }
  8.  
  9. QString statusMessage() const
  10. {
  11. return m_description;
  12. }
  13.  
  14. int line() const
  15. {
  16. return m_sourceLocation.line();
  17. }
  18.  
  19. int column() const
  20. {
  21. return m_sourceLocation.column();
  22. }
  23.  
  24. protected:
  25. virtual void handleMessage(QtMsgType type, const QString &description,
  26. const QUrl &identifier, const QSourceLocation &sourceLocation)
  27. {
  28. Q_UNUSED(type);
  29. Q_UNUSED(identifier);
  30.  
  31. m_description = description;
  32. m_sourceLocation = sourceLocation;
  33. }
  34.  
  35. private:
  36. QString m_description;
  37. QSourceLocation m_sourceLocation;
  38. };
To copy to clipboard, switch view to plain text mode 

thanks ;)