I am trying to parse xml and view it in program:
<list>
<item>
This i want
</item>
<item>
This i want 2 </item>
<item>This i want</item>
<item>This i want</item>
<item>This i want</item>
<item>This i want</item>
<item/>
<item/>
<item/>
</list>
With XmlListModel like this and view with ListModel:
XmlListModel {
id: itemmodel
source: page.dataURL
query: "/list"
XmlRole {
name: "item"
query: "item/string()"
}
}
SilicaListView {
width: 180; height: 300
model: itemmodel
delegate: Text { text: item }
}
When I run this it Qt creator says: "Unable to assign [undefined] to QString". What I am doing wrong? I am making app to Sailfish and this silicalistview is same as listview in qt. My goal is to view them like this:
This I want
This I want 2
and so on.
Thank you for your time!
The issue I think is that you only have one
<list>element and then all your<item>are in the same parent. So your query is looking for each<list>in your XML (only one) and then it prints only the first<item>element.Here is some code changing the
XmlRoleand thequerythat should work. I put the XML directly into thexmlproperty to simplify: