Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. xml parsing
Forum Updated to NodeBB v4.3 + New Features

xml parsing

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 1.8k 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.
  • bahman309B Offline
    bahman309B Offline
    bahman309
    wrote on last edited by
    #1

    hi any body
    i'm new in qt quick
    i have a problem in pars xml

    my xml file is

    //*************************************************

    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
    <album>
    <title>Air Show</title>
    <img src="http://xmlgrid.net/demo/pic/rsz_a1.jpg" />
    </album>
    <album>
    <title>Cruise</title>
    <img src="http://xmlgrid.net/demo/pic/rsz_c1.jpg" />
    </album>
    </gallery>

    //************************************************** **

    how can fetch image source from <img src ... > ?

    XmlListModel {
    id: imageModel
    //source: "http://xmlgrid.net/demo/sample1.xml"
    source: "/asset/sample1.xml"
    query: "/gallery/album"
    XmlRole { name: "imageSource"; query: "img/@src/string()" }
    XmlRole { name: "title"; query: "title/string()" }
    }

    T 1 Reply Last reply
    1
    • bahman309B bahman309

      hi any body
      i'm new in qt quick
      i have a problem in pars xml

      my xml file is

      //*************************************************

      <?xml version="1.0" encoding="UTF-8"?>
      <gallery>
      <album>
      <title>Air Show</title>
      <img src="http://xmlgrid.net/demo/pic/rsz_a1.jpg" />
      </album>
      <album>
      <title>Cruise</title>
      <img src="http://xmlgrid.net/demo/pic/rsz_c1.jpg" />
      </album>
      </gallery>

      //************************************************** **

      how can fetch image source from <img src ... > ?

      XmlListModel {
      id: imageModel
      //source: "http://xmlgrid.net/demo/sample1.xml"
      source: "/asset/sample1.xml"
      query: "/gallery/album"
      XmlRole { name: "imageSource"; query: "img/@src/string()" }
      XmlRole { name: "title"; query: "title/string()" }
      }

      T Offline
      T Offline
      tarod.net
      wrote on last edited by tarod.net
      #2

      @bahman309 Use @ to get the attributes.

      Example:

      
      import QtQuick 2.5
      import QtQuick.Controls 1.4
      import QtQuick.XmlListModel 2.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480    
      
          XmlListModel {
              id: xmlModel
              source: "/res/myxml.xml"
              query: "/gallery/album"
      
              XmlRole { name: "title"; query: "title/string()" }
              // query the img's src (the '@' indicates 'src' is an attribute, not an element)
              XmlRole { name: "img"; query: "img/@src/string()" }
          }
      
          ListView {
              width: 180; height: 300
              model: xmlModel
              delegate: Text { text: title + ": " + img }
          }
      }
      
      

      "Individually, we are one drop. Together, we are an ocean."

      1 Reply Last reply
      1
      • bahman309B Offline
        bahman309B Offline
        bahman309
        wrote on last edited by
        #3

        thank you for your reply
        I use @ but not work

        T 1 Reply Last reply
        0
        • bahman309B bahman309

          thank you for your reply
          I use @ but not work

          T Offline
          T Offline
          tarod.net
          wrote on last edited by
          #4

          @bahman309 Are you getting the title or is it also not working?

          I've uploaded my code to GitHub. Use it to check where the error is.

          "Individually, we are one drop. Together, we are an ocean."

          bahman309B 1 Reply Last reply
          1
          • T tarod.net

            @bahman309 Are you getting the title or is it also not working?

            I've uploaded my code to GitHub. Use it to check where the error is.

            bahman309B Offline
            bahman309B Offline
            bahman309
            wrote on last edited by bahman309
            #5

            @tarod.net
            it is so strange
            when i use your code in my project, I get the title but for image just get "undefined",
            and when i use your code in a new project, every thing is Ok ...

            thank you so much
            you are so kind and so expert

            T 1 Reply Last reply
            1
            • bahman309B bahman309

              @tarod.net
              it is so strange
              when i use your code in my project, I get the title but for image just get "undefined",
              and when i use your code in a new project, every thing is Ok ...

              thank you so much
              you are so kind and so expert

              T Offline
              T Offline
              tarod.net
              wrote on last edited by
              #6

              @bahman309 And what about your code in a new project?

              So, did you solve the problem? I could see more code if you want to or even the whole project. Just tell me where to download it.

              "Individually, we are one drop. Together, we are an ocean."

              1 Reply Last reply
              1
              • bahman309B Offline
                bahman309B Offline
                bahman309
                wrote on last edited by
                #7

                when i switch between the projects and then run my projects, it's work !!!

                T 1 Reply Last reply
                1
                • bahman309B bahman309

                  when i switch between the projects and then run my projects, it's work !!!

                  T Offline
                  T Offline
                  tarod.net
                  wrote on last edited by tarod.net
                  #8

                  @bahman309 Well, great then! :) Happy coding! Please, mark the post as solved.

                  "Individually, we are one drop. Together, we are an ocean."

                  1 Reply Last reply
                  1
                  • bahman309B Offline
                    bahman309B Offline
                    bahman309
                    wrote on last edited by
                    #9

                    thank you so much

                    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