Need help to parse Xml file

  • I have already open a topic here on another problem (solved) about a xml file that i need to parse. Now i'm trying to get the data and organize it.
    In this file i need to query the Item Value and it's children. To do that i use this code :

        XmlListModel {
            id: xmlModelValue
            source: Qt.resolvedUrl(path)
            query: "/Product/CommandClass/Value"
            namespaceDeclarations:"declare default element namespace '';"
            roles: [
                XmlRole { name: "type"; query: "@type/string()" },
                XmlRole { name: "genre"; query: "@genre/string()" },
                XmlRole { name: "instance"; query: "@instance/number()" },
                XmlRole { name: "index"; query: "0/number()" },
                XmlRole { name: "label"; query: "@label/string()" },
                XmlRole { name: "value"; query: "[object Object]/number()" },
                XmlRole { name: "min"; query: "@min/number()" },
                XmlRole { name: "max"; query: "@max/number()" },
                XmlRole { name: "size"; query: "@size/number()" },
                XmlRole { name: "help"; query: "Help/string()"}
            onStatusChanged: status === XmlListModel.Ready ? console.log("nbr instance value : "+xmlModelValue.count):console.log("loading data ...")

    To display the the data i use a ListView like that :

     ListView {
            anchors.fill: parent
            anchors.margins: 4
            model: xmlModelValue
                implicitHeight: childrenRect.height+5
                implicitWidth: childrenRect.width+10
                anchors.horizontalCenter : parent.horizontalCenter
                color: "transparent"
                Text {
                    horizontalAlignment: Qt.AlignHCenter
                    text: "Zwave configuration for : "+path
                    font.pixelSize: 32
                anchors.left: parent.left
                anchors.right: parent.right
                    Layout.preferredHeight: childrenRect.height+5
                    //                implicitWidth: parent.width
                    Layout.fillWidth: true
                    color: "transparent"
                    border.color: "gray"
                    border.width: 1
                    radius: 3
                        Text {
                            text: model.label
                            font.pixelSize: 20
                        Text {
                            text: "?"
                            font.pixelSize: 30
                                anchors.fill: parent
                Popup {
                         id: popup
                         x: main.width/2
                         width: 400
                         height: childrenRect.height
                         modal: true
                         focus: true
                         closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
                         Text {
                             anchors.fill: parent
                             wrapMode: Text.WordWrap
                             text: "Close"
                             onClicked: popup.close()

    This work fine. But i also need to query the item "Item" that is inside Value :

    <Value type="list" genre="config" instance="1" index="34" label="Reaction to alarms" value="63" min="1" max="63" size="1">
          <Help>Type of transmitted control frame for association group 1, activated via input IN1. The parameter allows to specify the type of alarm frame or to force transmission of control commands (BASIC_SET)</Help>
          <Item label="ALARM GENERIC" value="1" />
          <Item label="ALARM SMOKE" value="2" />
          <Item label="ALARM CO" value="4" />
          <Item label="ALARM CO2" value="8" />
          <Item label="ALARM HEAT" value="16" />
          <Item label="ALARM WATER" value="32" />
          <Item label="ALARM ALL" value="63" />

    I can't get the Item role like this :

    XmlRole { name: "Item"; query: "Item/string()"}

    Do you known how i can get it ? Do i need to create another XmlListModel ? If i did that i can't determine where to place it (in the good section) in my listView ...

Log in to reply

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