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. [Solved]XmlListModel problem
Qt 6.11 is out! See what's new in the release blog

[Solved]XmlListModel problem

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 2.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.
  • L Offline
    L Offline
    leaf
    wrote on last edited by
    #1

    Hi All,
    I have a problem when I trying get the data from xml.
    My question is how can I get 'Shanghai' and 'Beijing' at the same time,
    My code as below: @
    import QtQuick 1.0

    XmlListModel {
    id: cityModel

    source: "city.xml"  
    query: "/cities/city"    // ======> when I try to use '/cities/[A-B]/city' it is doesn't work.
    
    XmlRole { name: "name"; query: "name/string()" }
    XmlRole { name: "id";   query: "id/string()"   }
    

    }

    city.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <cities>
    <alphas><alpha>A</alpha></alphas>
    <A>
    <city><id>2231</id><name>Shanghai</name></city>
    </A>
    <alphas><alpha>B</alpha></alphas>
    <B>
    <city><id>3321</id><name>Beijing</name></city>
    </B>
    </cities>@

    Edit : please add @ tags,
    tags added; Eddy

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Reffy
      wrote on last edited by
      #2

      It's hard to understand this without formatting. Can you enclose the code in code tags so we can see better?

      I'm going to need to see the XML in its correct format.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrasser
        wrote on last edited by
        #3

        Hi,

        You should be able to get all cities using

        @query: "/cities//city"@

        or

        @query: "/cities/*/city"@

        If you only wanted e.g. the cities under A and B but not those under C, you could also try something like

        @query: "/cities/*[self::A or self::B]/city"@

        (in theory I think "/cities/A/city | /cities/B/city" should also work, but XmlListModel doesn't currently support this)

        Regards,
        Michael

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leaf
          wrote on last edited by
          #4

          Hi Michael,
          I used "/cities//city", now It works! Thank you very much.
          Can you give some information about the answer, If I can't find more information about 'query:' in Qt Assistant where can I find it?
          Regards,
          Leaf

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Slocan
            wrote on last edited by
            #5

            "Query" uses the Xpath syntax. You can find some info here:
            http://www.w3schools.com/xpath/xpath_syntax.asp

            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