XmlListModel & XmlRole with RSS



  • 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]



  • 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]



  • 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]



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

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



  • 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 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..



  • 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..



  • Thank you for your reply!

    i will try tonight and report back!



  • 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();
        }
    }
    

    }

    @-



  • 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 }
        }
    }
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.