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. Validating an XML file with a schema file
Forum Updated to NodeBB v4.3 + New Features

Validating an XML file with a schema file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.5k 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.
  • B Offline
    B Offline
    banerkx
    wrote on last edited by
    #1

    I am using QXmlSchemaValidator to validate an XML file. As far as I can tell, up to only one error is logged by QXmlSchemaValidator. Is there a way to get a list of all validation errors? Thanks.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      If have to admit that I haven't used QXmlSchemaValidator before but a quick look at the documentation reveals "QXmlSchemaValidator::setMessageHandler()":http://doc.qt.nokia.com/latest/qxmlschemavalidator.html#setMessageHandler.

      [quote]
      Changes the message handler for this QXmlSchemaValidator to handler. The schema validator sends all parsing and validation messages to this message handler. QXmlSchemaValidator does not take ownership of handler.
      [/quote]

      Is this not sufficient for you or does it not work as expected?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        banerkx
        wrote on last edited by
        #3

        I did set a message handler. My handler class has an STL vector data member that keeps track of the errors. The overridden handleMessage() method inserts an error message into this vector data member every time it is called. However, even though I know the XML file has more then 1 error, only the first error gets inserted into the vector data member. From what I can tell, QXmlSchemaValidator::validate() returns after the first XML error is encountered.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          [quote author="banerkx" date="1316813569"]From what I can tell, QXmlSchemaValidator::validate() returns after the first XML error is encountered. [/quote]

          That would actually seem pretty reasonable. After the first XML error, the rest of the document is then suspect and, thus, potentially unpredictable to validate further with any accuracy. No different than if you have a syntax problem in a C++ file; the compiler fails with an error upon the first bad line of code.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • AlicemirrorA Offline
            AlicemirrorA Offline
            Alicemirror
            wrote on last edited by
            #5

            @mllong: this happens in js or QML but a good compiler set a list of syntax error too. The problems in this case maybe that the further syntax errors after the first may depend from it (i.e. a classic unabalanced parentheses).

            If it is possible for you to explore the original xmls file by sections you can validate them in a loop to manage all the file despite if one or more - coherent - sections are wrong and can't be validated. This requires a pre-parse operation dividing the entire xml file in sub elements... Sure it is complicated.

            Enrico Miglino (aka Alicemirror)
            Balearic Dynamics
            Islas Baleares, Ibiza (Spain)
            www.balearicdynamics.com

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              @Alicemirror: I agree completely. However, I was just speaking in the context of the default behavior of QXmlSchemaValidator, and supposing as to why it might stop after the first error. That is to say, its behavior seems appropriate for a simple validator (i.e., XML either is or is not valid), but not an in-depth analysis tool.

              A validator is good for a quick "Not valid!" in the events where you just need to check while processing. If you're checking XML on-the-fly in a lightweight app, you're typically more concerned with a speedy Yes or No, rather than asking why. I think that QXmlSchemaValidator is designed to play that role well.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • AlicemirrorA Offline
                AlicemirrorA Offline
                Alicemirror
                wrote on last edited by
                #7

                @mlong: then, I agree with you. Excluding strange and rare cases, when a malformed xml error is retrieved it is sufficient for me to suppose that something is wrong in the data.

                Enrico Miglino (aka Alicemirror)
                Balearic Dynamics
                Islas Baleares, Ibiza (Spain)
                www.balearicdynamics.com

                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