Results 1 to 2 of 2

Thread: Qt XML validtion Error handling

  1. #1
    Join Date
    Feb 2017
    Posts
    1
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question Qt XML validtion Error handling

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

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt XML validtion Error handling

    Further analysis does not make sense because the successive errors can be the consequence of the first.

  3. The following user says thank you to Lesiok for this useful post:

    S.D. (16th February 2017)

Similar Threads

  1. Look for experoenced man in error handling
    By sylas in forum General Programming
    Replies: 4
    Last Post: 29th January 2017, 20:12
  2. Error handling guidelines?
    By bitflyer in forum Newbie
    Replies: 1
    Last Post: 2nd June 2010, 17:09
  3. QThread Error Handling
    By TheJim01 in forum Newbie
    Replies: 2
    Last Post: 8th April 2010, 15:54
  4. QNetworkReply error handling
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 25th August 2009, 10:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.