Reputation: 365
I'm trying to make a small RSS application with QML and want to query the Tagesschau atom feed. It basically looks like:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="/resources/xsl/atom_xsl.jsp" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<title>Lufthansa setzt Flüge nach Kairo aus</title>
</entry>
<entry>
<title>Telefonat zwischen Hunt und Sarif: Das Misstrauen bleibt</title>
</entry>
</feed>
The corresponding QML XmlListModel I have defined is this:
import QtQuick.XmlListModel 2.0
Item {
XmlListModel {
id: xmlfeed
source: "http://www.tagesschau.de/xml/atom/"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
}
Component {
id: feeditem
Label {
text: title
}
}
ListView {
id: feedlist
model: xmlfeed
clip: true
anchors { fill: parent; margins: 2 }
delegate: feeditem
}
}
However, this does not work. QML does not find any list items. I found out that the crucial part is the line:
<feed xmlns="http://www.w3.org/2005/Atom">
If I manually download the file and edit this line into just
<feed>
QML can parse it. Do you know, how to fix this? Do I need to improve my query
string or is this a bug in QML?
Upvotes: 1
Views: 627
Reputation: 12864
XPath itself doesn't have a way to bind a namespace prefix with a namespace. You can declare the namespace using XmlListModel.namespaceDeclarations. In your case that should look like the code in the example from the link above:
XmlListModel {
id: xmlfeed
source: "http://www.tagesschau.de/xml/atom/"
namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
}
Upvotes: 1