The xml
property of XmlListModel
must be of type string. Therefore you have to assign xhr.responseText
instead of xhr.responseXML
. Here is a minimal working example (using a data URI so simulate a server response):
import QtQuick 1.0
ListView {
width: 200; height: 200
delegate: Text {
text: name
}
model: XmlListModel {
id: xmlModel
query: "/names/name"
XmlRole { name: "name"; query: "string()" }
}
Component.onCompleted: {
/* <names>
<name>John</name>
<name>Max</name>
<name>Sandy</name>
</names> */
var dataURI = "data:application/xml;base64,PG5hbWVzPjxuYW1lPkpvaG48L25hbWU+PG5hbWU+TWF4PC9uYW1lPjxuYW1lPlNhbmR5PC9uYW1lPjwvbmFtZXM+"
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req.readyState == 4) {
xmlModel.xml = req.responseText; //<<<
}
};
req.open("get", dataURI, true);
req.send();
}
}