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. XmlRole - how to get values from query AND from parent element

XmlRole - how to get values from query AND from parent element

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.0k 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.
  • U Offline
    U Offline
    uruselfei
    wrote on last edited by
    #1

    hi,

    I have an XML like this:
    @<services>
    <service id="1">
    <option id="1" value="1"/>
    <option id="2" value="2"/>
    </service>
    <service id="2">
    <option id="1" value="1"/>
    <option id="2" value="2"/>
    </service>
    </services>@

    I need to get list with options values AND with service IDs, like (service, option id, value):
    1, 1, 1
    1, 2, 2
    2, 1, 1
    2, 2, 2

    I was trying to set query to "/services/service/option". this gives all options, but i can't get service ID from parent element.
    XmlRole { name: "serviceId"; query: "../@id/string()" } -- gives empty result. also tried several other XPath tricks, still nothing.

    unfortunately, i can't change XML, so, it is needed to solve this issue with other possibilities (preferably with standard QML)

    thanks in advance

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deimos
      wrote on last edited by
      #2

      I think the query should only “/services/service" with

      @XmlRole { name: “service”; query: “@id/string()” }
      XmlRole { name: “option”; query: “@id[1]/string()” }
      XmlRole { name: “option”; query: “@value[1]/string()” }@

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uruselfei
        wrote on last edited by
        #3

        yep, this would work if i need only one service. but i need them all..

        currently i made workaround (not sure if they are correct from rules point of view, but anyway they work for me)

        1. i get only "/services/service" and pass model to ListView. in ListView delegate i have another model with
          @
          property string serviceId
          query: "/services/service[@id=" + serviceId + "]/options"
          @
          this is like "loop-in-loop"
        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