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



  • 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



  • 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: “[object Object][1]/string()” }@



  • 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"

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.