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. How do we store a parsed xml file in Qt?
Forum Updated to NodeBB v4.3 + New Features

How do we store a parsed xml file in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 1.6k Views 4 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.
  • mrjjM mrjj

    @varshit
    Hi
    but in what way do you need to store it ?
    Like a tree so nodes have child nodes
    and each node has properties and properties has name and value ?

    V Offline
    V Offline
    varshit
    wrote on last edited by
    #9

    @mrjj

    Hi

    I am attaching a sample XML file and its output, Now I need to store this output in a data structure. for example, the data structure can be QMap, QStack or QHash or anything that has advantages. Screenshot (127).png Screenshot (126).png

    Thank you

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #10

      Hi
      What data structure that works best would depend on what you need to do with after.
      Do you need this data to be exposed to QML ?
      If yes, we should use a data type that QML understand then.
      Also Qmap would allow you to look up that data using a key but do you need that ?

      V 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        What data structure that works best would depend on what you need to do with after.
        Do you need this data to be exposed to QML ?
        If yes, we should use a data type that QML understand then.
        Also Qmap would allow you to look up that data using a key but do you need that ?

        V Offline
        V Offline
        varshit
        wrote on last edited by
        #11

        @mrjj

        Hi, Thank you for helping me at this time.

        yes, I need this data to be exposed to QML.
        Yes, I need to store this data in keys and values style.

        here's where I am going wrong with what data structure should I use. can you suggest me a data structure that understands the QML?

        Pablo J. RoginaP 1 Reply Last reply
        0
        • V varshit

          @mrjj

          Hi, Thank you for helping me at this time.

          yes, I need this data to be exposed to QML.
          Yes, I need to store this data in keys and values style.

          here's where I am going wrong with what data structure should I use. can you suggest me a data structure that understands the QML?

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #12

          @varshit said in How do we store a parsed xml file in Qt?:

          e a data structure that understands the QML?

          Are you trying to create a UI in QML based on that XML? If so it looks like you may want to start creating QML components as you parse the XML then

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          V 1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @varshit said in How do we store a parsed xml file in Qt?:

            e a data structure that understands the QML?

            Are you trying to create a UI in QML based on that XML? If so it looks like you may want to start creating QML components as you parse the XML then

            V Offline
            V Offline
            varshit
            wrote on last edited by
            #13

            @Pablo-J-Rogina

            Hi

            We want to create a UI inQML based on that XML.
            We created the QML components using QComponents

            Now I want to store the parsed XML file in a QMap or QHash or etc or in any container class.
            Please help me with the storing part.

            Thank you

            jsulmJ JonBJ 2 Replies Last reply
            0
            • V varshit

              @Pablo-J-Rogina

              Hi

              We want to create a UI inQML based on that XML.
              We created the QML components using QComponents

              Now I want to store the parsed XML file in a QMap or QHash or etc or in any container class.
              Please help me with the storing part.

              Thank you

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

              @varshit What exact problem do you have with storing key/value pairs from XML in QMap/QHash which you already print out?

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

              V 1 Reply Last reply
              2
              • V varshit

                @Pablo-J-Rogina

                Hi

                We want to create a UI inQML based on that XML.
                We created the QML components using QComponents

                Now I want to store the parsed XML file in a QMap or QHash or etc or in any container class.
                Please help me with the storing part.

                Thank you

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

                @varshit
                May I ask again why you wish to try to turn this into QMap or QHash?

                You're going to have to store it as a "recursive tree" of QMap/QHashes, to allow for the structure and avoid duplicates. For example, an XML document could easily have multiple nodes named /a/b, so you cannot easily just use a "flat" key for your maps/hashes to avoid all the nesting....

                I wrote earlier that you already have a parsed structure which captures the whole XML document. And it's a QDomDocument with QDomNodes. You don't have to do your own parsing/copying, because it's done for you, and you can search/walk that as required. It can also serialize to/deserialize from text. So you're done!?

                V 1 Reply Last reply
                1
                • JonBJ JonB

                  @varshit
                  May I ask again why you wish to try to turn this into QMap or QHash?

                  You're going to have to store it as a "recursive tree" of QMap/QHashes, to allow for the structure and avoid duplicates. For example, an XML document could easily have multiple nodes named /a/b, so you cannot easily just use a "flat" key for your maps/hashes to avoid all the nesting....

                  I wrote earlier that you already have a parsed structure which captures the whole XML document. And it's a QDomDocument with QDomNodes. You don't have to do your own parsing/copying, because it's done for you, and you can search/walk that as required. It can also serialize to/deserialize from text. So you're done!?

                  V Offline
                  V Offline
                  varshit
                  wrote on last edited by
                  #16

                  @JonB

                  Hi
                  Now my main part is to store that output data (image inserted above) in [QMap<QString, QMap<QString, QString>>;] this data structure.

                  Thank you

                  JonBJ 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @varshit What exact problem do you have with storing key/value pairs from XML in QMap/QHash which you already print out?

                    V Offline
                    V Offline
                    varshit
                    wrote on last edited by
                    #17

                    @jsulm

                    Hi
                    I am not able to understand or figure out how to store these Key-value pairs in the above-mentioned data structure.

                    1 Reply Last reply
                    0
                    • V varshit

                      @JonB

                      Hi
                      Now my main part is to store that output data (image inserted above) in [QMap<QString, QMap<QString, QString>>;] this data structure.

                      Thank you

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

                      @varshit
                      So your top-level QMap<QString, QMap<QString, QString>> will have keys breakfast_menu, Veg, etc. Each one will have its own QMap<QString, QString> as value. Those inner QMaps will have keys menu1, menu2 with values veg, non-veg, etc. Nothing else to say.

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #19

                        @varshit said in How do we store a parsed xml file in Qt?:

                        [QMap<QString, QMap<QString, QString>>;]

                        It would be like

                             using  MemberMap = QMap<QString, QString>;
                             QMap<QString, MemberMap> items;
                             
                             MemberMap m1;
                             m1["text"]="value";
                             ...
                             items["ID"]=m1;
                             
                             MemberMap m2;
                             m1["text"]="value";
                             ...
                             items["ID"]=m2;
                             
                        

                        But using your real data for key value and ID

                        1 Reply Last reply
                        2

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved