Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    QML and Qt Quick
    2
    3
    1664
    Loading More Posts
    • 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
      uruselfei last edited by

      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 Reply Quote 0
      • D
        deimos last edited by

        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 Reply Quote 0
        • U
          uruselfei last edited by

          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 Reply Quote 0
          • First post
            Last post