Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. XmlListModel & XmlRole with RSS
Forum Updated to NodeBB v4.3 + New Features

XmlListModel & XmlRole with RSS

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 5 Posters 8.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ny-hardcore
    wrote on last edited by
    #1

    Hi, i'm trying to parse following xml feed with XmlListModel, delegate and Listview

    @
    <GetProgramGuideResponse>
    <ProgramGuide>
    <Channels>
    <Channel name=Channel1>
    <Program title=program1>
    <Program title=program2>
    <Program title=program3>
    </Channel>
    <Channel name=Channel2>
    <Program title=program1>
    <Program title=program2>
    <Program title=program3>
    </Channel>
    @

    But i'm having a hard time with the query,
    i can get all the channels OR all the programm titles,

    But what i really want is a per channel list of titles like so:
    channel1, title
    channel1, title
    channel2, title
    channel2, title

    my xmllistmodel looks like this:

    @
    XmlListModel {

     id: xmlModel
     source: "http://192.168.1.65:6544/Myth/GetProgramGuide?StartTime=2011-02-07T20:00:00&EndTime=2011-02-07T23:00:00&Details=0&NumOfChannels=10"
     query: "/GetProgramGuideResponse/ProgramGuide/Channels"
    
     XmlRole { name: "channel"; query: "Channel/&#x40;channelName/string()" }
     XmlRole { name: "title"; query: "Channel/Program/&#x40;title/string()" }
     XmlRole { name: "category"; query: "Channel/Program/&#x40;category/string()" }
     XmlRole { name: "startTime"; query: "Channel/Program/&#x40;startTime/string()" }
    

    @

    this all returns undefined, the error on console is:
    @
    Error FORG0006 in Unknown location: Effective Boolean Value cannot be calculated for a sequence containing two or more atomic values.
    @
    googleing this doens't give me any clues...

    I suspect this has to do with the fact that every channel can have more than one program, if i parse rss with one program per channel it works as expected...

    Is this at all possible? If so, can someone point me into the right direction?

    [EDIT: code formatting, please use @-tags, Volker]

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rburdick
      wrote on last edited by
      #2

      Another related question:

      How do you parse values out of XML elements that are in tags with namespaces? For example, in the following:

      @
      <media:content xmlns:media="http://search.yahoo.com/mrss"
      url="http://myserver.com/sample.jpg"
      type="image/jpeg"
      medium="image"
      height="76"
      width="76">
      @

      I have the following XmlListModel:

      @
      XmlListModel {
      id: newsModel
      source: mainWindow.currentFeed
      query: "/rss/channel/item"
      namespaceDeclarations: "declare namespace media='http://search.yahoo.com/mrss';"

          XmlRole { name: "title"; query: "title/string()" }
          XmlRole { name: "link"; query: "link/string()" }
          XmlRole { name: "description"; query: "description/string()" }
          XmlRole { name: "imageUrl"; query: "media:content/&#x40;url" }
      }
      

      @

      Everything works except for the imageUrl query. If anyone has successfully parsed XML values out of namespace based XML, I'd love to see how it was done.

      [EDIT: code formatting, Volker]

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ny-hardcore
        wrote on last edited by
        #3

        Update to orginal post about parsing xml feed (not the hijack about namespaces...)

        I made my listmodel like this now:

        @
        id: xmlModel
        source: "http://192.168.1.65:6544/Myth/GetProgramGuide?StartTime=2011-02-08T22:00:00&EndTime=2011-02-08T23:00:00&Details=0&NumOfChannels=100"
        query: "/GetProgramGuideResponse/ProgramGuide///Program"

         XmlRole { name: "channel"; query: "Channel/&#x40;channelName/string()" }
         XmlRole { name: "title"; query: "&#x40;Title/string()" }
         XmlRole { name: "category"; query: "&#x40;Category/string()" }
         XmlRole { name: "startTime"; query: "&#x40;startTime/string()" }
        

        @
        AT=@ (tags mess code up?)

        i get all 'programms' but not the @channelName from channel..

        i tried the solution in this thread about parents..
        http://developer.qt.nokia.com/forums/viewthread/3638/
        but to no avail..
        maybe because i want the attribute of the parent? i studied xpath tutorials but can't seem to find an answer to my question..

        [EDIT: fixed @-Signs, Volker]

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          [quote author="ny-hardcore" date="1297203248"]
          AT=@ (tags mess code up?)
          [/quote]

          You can use &#x40; to insert an @-tag into a code section.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • G Offline
            G Offline
            geronik
            wrote on last edited by
            #5

            One solution could be to use two models for each tag, namely one model for channels and one for the programs. The model for the programs should use the name of the channel..

            1 Reply Last reply
            0
            • N Offline
              N Offline
              ny-hardcore
              wrote on last edited by
              #6

              [quote author="geronik" date="1297238147"]One solution could be to use two models for each tag, namely one model for channels and one for the programs. The model for the programs should use the name of the channel..[/quote]

              I thought about this solution, but how would i make the listview present the correct Parent > Childeren ?
              The first model would collect al channels, the second all programs.
              Should i make a 'nested' listview then? (is this possible?)

              @
              Listview with Parent
              model of Parents
              delegate of parents
              Listview with Childeren
              model of children
              delegate of Children
              @

              Or do i have to do something in the delegate, and use one delegate for both?

              excuse me if the above doesn't make sense, i'm very new to qml and programming in general..

              1 Reply Last reply
              0
              • G Offline
                G Offline
                geronik
                wrote on last edited by
                #7

                You could use a delegate and a model for each type of tag :

                ProgramGuide.qml

                @
                XmlListModel{
                ..

                query: "/path/to/channels"
                

                XmlRole{ name:"channelList" query:"@name/string()" }

                }
                @

                ProgramGuideItem.qml

                @ListView{
                model:ProgramGuide{}

                delegate: ChannelsDelegate{ }

                }@

                ChannelsByList.qml

                @
                XmlListModel{
                ..

                query: "path/to/channels[@name = _channelListName]/channel"

                XmlRole{ name:"channelName" query:"@name/string()" }

                }@

                ChannelsDelegate.qml

                @
                Item{
                ..
                ListView{

                  model: ChannelsByList{ _channelListName: name}
                
                 delegate: ChannelDelegate{ }
                

                }@

                ChannelDelegate.qml

                @
                Item{
                ..

                model: ProgramsByChannel{ _channeName: name }

                delegate: ProgramDelegate{ }

                }@

                ..

                I hope I didn't create any mess..

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  ny-hardcore
                  wrote on last edited by
                  #8

                  Thank you for your reply!

                  i will try tonight and report back!

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    ny-hardcore
                    wrote on last edited by
                    #9

                    i'm sorry.. i tried but failed..

                    is it possible you mixed up some names?

                    I have following so far:

                    MythScheduleInfo.qml
                    @-

                    import QtQuick 1.0

                    XmlListModel {
                    id: scheduleInfo
                    source: "http://192.168.1.65:6544/Myth/GetProgramGuide?StartTime=2011-02-11T22:00:00&EndTime=2011-02-11T23:00:00&Details=0&NumOfChannels=10"
                    query: "/GetProgramGuideResponse/ProgramGuide/Channels/*/Program"

                     XmlRole { name: "title"; query: "title/string()" }
                     XmlRole { name: "category"; query: "category/string()" }
                     XmlRole { name: "startTime"; query: "startTime/string()" }
                     }
                    

                    @-

                    MythChannelList.qml (isn't used atm but returns all channel names)
                    @-

                    import QtQuick 1.0

                    XmlListModel {
                    id: channelList
                    source: "http://192.168.1.65:6544/Myth/GetProgramGuide?StartTime=2011-02-11T22:00:00&EndTime=2011-02-11T23:00:00&Details=0&NumOfChannels=10"
                    query: "/GetProgramGuideResponse/ProgramGuide/Channels/Channel"

                         XmlRole { name: "channelList"; query: "channelName/string()" }
                    
                          }
                    

                    @-

                    ScheduleDelegate.qml
                    @-
                    import QtQuick 1.0

                    Component {
                    id: scheduleDelegate
                    Item {
                    width: 800; height: 100
                    Column {
                    Text {
                    font.pixelSize: 20
                    clip: true
                    wrapMode: Text.WordWrap
                    textFormat: Text.RichText
                    text: '<b>Title:</b> ' + title }

                            Text {
                                font.pixelSize: 16
                                clip: true
                                wrapMode: Text.WordWrap
                                textFormat: Text.RichText
                                text: '<b>Starttime:</b> ' + startTime }
                    
                                Text {
                                font.pixelSize: 14
                                clip: true
                                wrapMode: Text.WordWrap
                                textFormat: Text.RichText
                                text: '<b>Description:</b> '  }
                    
                            Text {
                                font.pixelSize: 14
                                clip: true
                                wrapMode: Text.WordWrap
                                textFormat: Text.RichText
                                text: '<b>Category:</b> ' + category }
                            }
                    }
                    

                    }
                    @-

                    ScheduleMenu.qml
                    @-

                    import Qt 4.7

                    Item {
                    anchors.fill: parent;

                    Text {
                        id: text
                        anchors {
                            left: parent.left
                            topMargin: 40
                            top: parent.Top
                        }
                        text: "Schedule Information"
                        font.pixelSize: 55
                        color: "white"
                        style: Text.Raised;  styleColor: "#1d1d1d";
                    }
                    
                    ScheduleDelegate { id: scheduleDelegate }
                    
                    Item {
                        ListView {
                            anchors {
                                left: parent.horizontalCenter
                                top: parent.top
                                topMargin: 100
                                leftMargin: 250 }
                            width: 600
                            height: 600
                            model: mythScheduleInfo
                            delegate: scheduleDelegate
                            MouseArea {
                                anchors.fill: parent
                                onClicked: xmlModel.refresh(); }
                                    }
                    }
                    
                    Column {
                        anchors {
                            verticalCenter: parent.verticalCenter
                            top: text.bottom
                            topMargin: 20
                        }
                        spacing: 20
                        Button {
                            width: 180; height: 93
                            text: "Status"
                            onClicked: main.state = "StatusState"
                        }
                        Button {
                            width: 180; height: 93
                            text: "Schedule"
                            onClicked: Qt.quit();
                        }
                        Button {
                            width: 180; height: 93
                            text: "Quit"
                            onClicked: Qt.quit();
                        }
                    }
                    

                    }

                    @-

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      blam
                      wrote on last edited by
                      #10

                      You can make a nested view by having a model + delegate for the channels, then in that delegate, have a model + delegate for the programs.

                      E.g.

                      @
                      ListView {
                      width: 300; height: 500
                      model: XmlListModel {
                      source: ...
                      query: "/GetProgramGuideResponse/ProgramGuide/Channels/Channel"
                      XmlRole { name: "channel"; query: "@name/string()" }
                      }

                      delegate: Row {
                          Text { text: channel }
                      
                          ListView {
                              width: 300; height: 100
                              model: XmlListModel {
                                  source: ...
                                  query: "/GetProgramGuideResponse/ProgramGuide/Channels/Channel[&#x40;name='" + channel + "']"
                                  XmlRole { name: "programTitle"; query: "Program[1]/&#x40;title/string()" }
                              }
                              delegate: Text { text: programTitle }
                          }
                      }
                      

                      }
                      @

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved