Need help to parse Xml file
Unsolved
QML and Qt Quick
-
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 'http://code.google.com/p/open-zwave/';" roles: [ XmlRole { name: "type"; query: "@type/string()" }, XmlRole { name: "genre"; query: "@genre/string()" }, XmlRole { name: "instance"; query: "@instance/number()" }, XmlRole { name: "index"; query: "@index/number()" }, XmlRole { name: "label"; query: "@label/string()" }, XmlRole { name: "value"; query: "@value/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 header: Rectangle{ implicitHeight: childrenRect.height+5 implicitWidth: childrenRect.width+10 anchors.horizontalCenter : parent.horizontalCenter color: "transparent" Text { horizontalAlignment: Qt.AlignHCenter text: "Zwave configuration for : "+path color:"white" font.pixelSize: 32 } } delegate: RowLayout{ anchors.left: parent.left anchors.right: parent.right Rectangle{ Layout.preferredHeight: childrenRect.height+5 // implicitWidth: parent.width Layout.fillWidth: true color: "transparent" border.color: "gray" border.width: 1 radius: 3 RowLayout{ Text { text: model.label color:"white" font.pixelSize: 20 } Text { text: "?" color:"white" font.pixelSize: 30 MouseArea{ anchors.fill: parent onClicked: popup.open() } } } } Popup { id: popup x: main.width/2 width: 400 height: childrenRect.height modal: true focus: true closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent ColumnLayout{ Text { anchors.fill: parent text: model.help wrapMode: Text.WordWrap } Button{ 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" /> </Value>
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 ...