PDA

View Full Version : Qt XmlRole problem



jjvainstein
7th October 2011, 04: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, 21: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, 04: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, 09:37
Please define "don't work", my crystal ball is out of order.

jjvainstein
8th October 2011, 13:16
Sorry, this is the error: QML XmlRole: invalid query: "yweather:location/@city/string()"

wysota
8th October 2011, 15: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
9th October 2011, 00: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, 10:34
You have to learn XQuery.