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. QDomDocument::setContent() and error parsing
QtWS25 Last Chance

QDomDocument::setContent() and error parsing

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 1.4k Views
  • 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by Robert Hairgrove
    #1

    I have a lot of pre-existing code which uses QDomDocument and related. classes (yes, I know it is deprecated, but we still use it). In my application, I load a configuration file which is in XML format. I also have an XML schema file (.xsd) which resides in the same folder as the XML file.

    My question: When I call setContent(), I can receive any error message as well as the line and column number in the file where the error occurred. According to the Qt documentation:

    If a parse error occurs, this function returns false and the error message is placed in *errorMsg,
    the line number in *errorLine and the column number in *errorColumn (unless the associated pointer 
    is set to 0); otherwise this function returns true. The various error messages are described in the 
    QXmlParseException class documentation.
    

    But looking at the different error messages in the QXmlParseException documentation, it appears to expect a DTD file when loading the XML. Does it also validate against a schema file if the XML includes a reference to it? Or do I have to do this separately?

    It would be enough for my application to know whether validation succeeded or not; line and column numbers would also be good to have, but not vitally important.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Robert-Hairgrove said in QDomDocument::setContent() and error parsing:

      yes, I know it is deprecated, but we still use it

      where did you read this?

      Does it also validate against a schema file if the XML includes a reference to it?

      afaics no, that's what Qt XML Patterns was for.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 2 Replies Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Robert-Hairgrove said in QDomDocument::setContent() and error parsing:

        yes, I know it is deprecated, but we still use it

        where did you read this?

        Does it also validate against a schema file if the XML includes a reference to it?

        afaics no, that's what Qt XML Patterns was for.

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thank you.

        I suppose I misunderstood the documentation here?
        https://doc.qt.io/qt-5/qtxml-module.html#details

        But I am glad to know that it is still officially supported. I will take a look at Qt XML Patterns now.

        jsulmJ 1 Reply Last reply
        0
        • R Robert Hairgrove

          @Christian-Ehrlicher Thank you.

          I suppose I misunderstood the documentation here?
          https://doc.qt.io/qt-5/qtxml-module.html#details

          But I am glad to know that it is still officially supported. I will take a look at Qt XML Patterns now.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Robert-Hairgrove Do you mean "Note that the module will not receive additional features anymore"? This does not mean it is depricated.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Robert-Hairgrove Do you mean "Note that the module will not receive additional features anymore"? This does not mean it is depricated.

            R Offline
            R Offline
            Robert Hairgrove
            wrote on last edited by
            #5

            @jsulm Yes, that is what I thought. Good to know that it is not deprecated.

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Robert-Hairgrove said in QDomDocument::setContent() and error parsing:

              yes, I know it is deprecated, but we still use it

              where did you read this?

              Does it also validate against a schema file if the XML includes a reference to it?

              afaics no, that's what Qt XML Patterns was for.

              R Offline
              R Offline
              Robert Hairgrove
              wrote on last edited by
              #6

              @Christian-Ehrlicher Now that Qt 6.0 has been released, I see that the XML patterns module was removed entirely from this version of Qt. What do I need to do, building with Qt 6, in order to validate an XML document against a schema XSD document stored in Qt resources, for example? I haven't found any relative documentation which explains how to compensate for the removal of XML patterns.

              Resetting this thread to "unsolved".

              Christian EhrlicherC 1 Reply Last reply
              1
              • R Robert Hairgrove

                @Christian-Ehrlicher Now that Qt 6.0 has been released, I see that the XML patterns module was removed entirely from this version of Qt. What do I need to do, building with Qt 6, in order to validate an XML document against a schema XSD document stored in Qt resources, for example? I haven't found any relative documentation which explains how to compensate for the removal of XML patterns.

                Resetting this thread to "unsolved".

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Robert-Hairgrove Don'T use Qt6 or an external xsd validation library. You will not get it back in Qt6 except you write it on your own.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                R 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @Robert-Hairgrove Don'T use Qt6 or an external xsd validation library. You will not get it back in Qt6 except you write it on your own.

                  R Offline
                  R Offline
                  Robert Hairgrove
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher Thank you.

                  I assume you meant to write: "Don't use Qt6, or else use an external xsd validation library"?

                  I know that I could do this with Xerces, but would like to avoid the dependency if I can. Does anyone have suggestions for a lightweight external library? It should work on Linux and Windows, if possible.

                  JonBJ 1 Reply Last reply
                  0
                  • R Robert Hairgrove

                    @Christian-Ehrlicher Thank you.

                    I assume you meant to write: "Don't use Qt6, or else use an external xsd validation library"?

                    I know that I could do this with Xerces, but would like to avoid the dependency if I can. Does anyone have suggestions for a lightweight external library? It should work on Linux and Windows, if possible.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @Robert-Hairgrove
                    I feel your pain. We won't be thanked/will be shot down for saying this, but if you are saying the QXml... classes are gone from Qt 6(?) that is a sad, retrograde step for those of us who use XML. In that case I just hope they drop the JSON support too....

                    R 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Robert-Hairgrove
                      I feel your pain. We won't be thanked/will be shot down for saying this, but if you are saying the QXml... classes are gone from Qt 6(?) that is a sad, retrograde step for those of us who use XML. In that case I just hope they drop the JSON support too....

                      R Offline
                      R Offline
                      Robert Hairgrove
                      wrote on last edited by
                      #10

                      @JonB The removed features are listed here. There are still classes which are named beginning with QXml..., but I don't know if they still work as they did before:

                      https://wiki.qt.io/New_Features_in_Qt_6.0#Removed_Modules

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Robert Hairgrove
                        wrote on last edited by
                        #11

                        I bit the bullet and now am using Xerces. It's fairly easy to use, but quite a large library to install. At least it works on both Windows and Linux, and the licensing is agreeable.

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          BillouParisPro
                          wrote on last edited by BillouParisPro
                          #12

                          Hi,
                          I am confrontied to the same issue. I have a Qt5 application relying on QXmlSchemaValidator validator; to validate an xml against an xsd file. Not sure what shall be done to port my application to Qt6? Does the QXmlStreamReader do this check implicitely?
                          Regards,
                          Billl

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Online
                            Christian EhrlicherC Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            QXmlStreamReader is for reading xml, not for validating. You have to use another 3rd party library.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            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