View Full Version : Qt XmlRole problem
jjvainstein
7th October 2011, 03:47
Hi everyone, I have a problem with XmlRole. I'm trying to parse this:
http://weather.yahooapis.com/forecastrss?p=ARBA0004&u=c
I'm using:
XmlRole{name: "city"; query: "yweather:location/@temp/string()"}
but it produce this error:
QML CodeCityModel: invalid query: "yweather:location/@temp/string()"
I hope someone can help me.
wysota
7th October 2011, 20:17
First of all I don't see a "yweather:location" tag with a "temp" attribute in it. Furthermore I think it should be "//yweather:location". So "//yweather:location/@city" should work.
jjvainstein
8th October 2011, 03:33
You have reason, I made a mistake. However, my code don't work. This is my code:
XmlListModel{
id: weatherModel
source: "http://weather.yahooapis.com/forecastrss?p=ARBA0004&u=c"
query: "/rss/channel"
signal sendXmlData (string city, string temperature, string status, string icon)
XmlRole{name: "city"; query: "yweather:location/@city/string()"}
}
wysota
8th October 2011, 08:37
Please define "don't work", my crystal ball is out of order.
jjvainstein
8th October 2011, 12:16
Sorry, this is the error: QML XmlRole: invalid query: "yweather:location/@city/string()"
wysota
8th October 2011, 14:54
The following xquery works for me:
declare namespace yweather = "http://xml.weather.yahoo.com/ns/rss/1.0";
doc("focus.xml")/rss/channel/yweather:location/@city/string()
so your code should read:
XmlListModel{
id: weatherModel
source: "http://weather.yahooapis.com/forecastrss?p=ARBA0004&u=c"
query: "/rss/channel"
namespaceDeclarations: "declare namespace yweather = 'http://xml.weather.yahoo.com/ns/rss/1.0';"
XmlRole{ name: "city"; query: "yweather:location/@city/string()" }
}
jjvainstein
8th October 2011, 23:52
Thanks a lot. However, I still don't understand well how to work with this kind of query.
Thanks again.
wysota
9th October 2011, 09:34
You have to learn XQuery.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.