01-17-2013 01:52 AM
Hello,
I'm getting my xml from an RSS feed.
I put is in a datamodel.
I now want to display that feed on a listView. ie: image on the left and title+description on the right.
This is what i have tried so far.:
ListView {
ListView {
id: myListView
// Associate the list view with the data model that's defined in the
// attachedObjects list
dataModel: dataModel
listItemComponents: [
ListItemComponent {
type: "item"
Container{
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
//container{
//preferredWidth: 100.0
ImageView {
imageSource: ListItemData.description.img
preferredWidth: 150.0
preferredHeight: 300.0
//opacity: itemRoot.ListItem.selected ? 1.0 : 0.5
}
//}
Container{
preferredHeight: 300.0
StandardListItem {
//reserveImageSpace: false
preferredHeight: 300.0
title: ListItemData.title
description: ListItemData.description
}
}
} // end of Container
}
]
} // end of ListViewI can read the title but, i can read the image and the description's paragraph.
Here is the url of the RSS: http://www.carmag.co.za/category/news/feed/
This is what the description looks like:
<description> <![CDATA[ <img width="216" height="122" src="http://www.carmag.co.za/wp-content/uploads/2013/01/16-216x122.jpg" class="attachment-thumbnail wp-post-image" alt="Is this the production-ready Honda NSX?" title="Is this the production-ready Honda NSX?" /><br> <p>Whether it was planned or not, hours before Honda was about to showcase a follow-up concept of the new NSX sportscar, these pictures of what may be a production-spec Acura (Honda) NSX have leaked onto the ‘web. From what we can gather, subtle changes have been made to the car’s exterior. But, more importantly, these … <a href="http://www.carmag.co.za/news/production-ready-hond a-nsx/"></a></p><p>The post <a href="http://www.carmag.co.za/news/production-ready-hond a-nsx/">Is this the production-ready Honda NSX?</a> appeared first on <a href="http://www.carmag.co.za">CarMag.co.za</a>.</p> ]]> </description>
Anyone has suggestions? ![]()
Thanks,
Herve
01-17-2013 02:19 AM
Can't your read the description just by saying ListItemData.description?
Because the image is embedded in the description as an html img tag, it's offcourse logical that you can't read it directly out of the xml file.
What I think you have to do is the following.
-> Download the rss file
-> Process the xml file
- You have to get the url out of the img tag in the description (best option is a regex)
- If you have that url, create a new tag in that same rss item named <image></image>
- Put the url between those image tags
-> Save the xml file to the device
-> Show it in the datamodel
I guess the next piece of code can do for the regex
RegExp("<img width=\"[0-9]+\" height=\"[0-9]+\" src="([^\"]*)" class=\"attachment-thumbnail wp-post-image\" alt=\"([^\"]*)\" title=\"([^\"]*)\" />");Now you can capture the src, the alt and the title if you need them.
The next piece of code works for me
QRegExp regex("<img width=\"[0-9]+\" height=\"[0-9]+\" src=\"([^\"]*)\" class=\"attachment-thumbnail wp-post-image\" alt=\"([^\"]*)\" title=\"([^\"]*)\" />");
regex.setMinimal(true);
regex.setCaseSensitivity(Qt::CaseInsensitive);
QString xml("<description><![CDATA[<img width=\"216\" height=\"122\" src=\"http://www.carmag.co.za/wp-content/uploads/2013/01 /16-216x122.jpg\" class=\"attachment-thumbnail wp-post-image\" alt=\"Is this the production-ready Honda NSX?\" title=\"Is this the production-ready Honda NSX?\" /><br> <p>Whether it was planned or not, hours before Honda was about to showcase a follow-up concept of the new NSX sportscar, these pictures of what may be a production-spec Acura (Honda) NSX have leaked onto the ‘web. From what we can gather, subtle changes have been made to the car’s exterior. But, more importantly, these … <a href=\"http://www.carmag.co.za/news/production-ready-hond a-nsx/\"></a></p><p>The post <a href=\"http://www.carmag.co.za/news/production-ready-hond a-nsx/\">Is this the production-ready Honda NSX?</a> appeared first on <a href=\"http://www.carmag.co.za\">CarMag.co.za</a>.</p>]]></description>");
int position = regex.indexIn(xml);
if(position != -1) {
QString src=regex.cap(1);
QString alt = regex.cap(2);
QString title = regex.cap(3);
}
01-17-2013 03:30 AM
Wow!
My C++ is good but, Both Qt and regular expressions are new cocepts to me.
I will still try what you suggested.
Thanks