Results 1 to 8 of 8

Thread: Qt XmlRole problem

  1. #1
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt XmlRole problem

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt XmlRole problem

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt XmlRole problem

    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()"}
    }

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt XmlRole problem

    Please define "don't work", my crystal ball is out of order.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt XmlRole problem

    Sorry, this is the error: QML XmlRole: invalid query: "yweather:location/@city/string()"

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt XmlRole problem

    The following xquery works for me:

    xquery Code:
    1. declare namespace yweather = "http://xml.weather.yahoo.com/ns/rss/1.0";
    2. doc("focus.xml")/rss/channel/yweather:location/@city/string()
    To copy to clipboard, switch view to plain text mode 

    so your code should read:
    javascript Code:
    1. XmlListModel{
    2. id: weatherModel
    3. source: "http://weather.yahooapis.com/forecastrss?p=ARBA0004&u=c"
    4. query: "/rss/channel"
    5. namespaceDeclarations: "declare namespace yweather = 'http://xml.weather.yahoo.com/ns/rss/1.0';"
    6. XmlRole{ name: "city"; query: "yweather:location/@city/string()" }
    7. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt XmlRole problem

    Thanks a lot. However, I still don't understand well how to work with this kind of query.

    Thanks again.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt XmlRole problem

    You have to learn XQuery.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.