From 12280c6a0f634e1271b7c94b21ff58737ed42b10 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 11 Jul 2012 20:26:12 +0300 Subject: [PATCH] Fix RSS parsing --- src/rss/rssarticle.cpp | 43 +++++++++++++++++++------------------- src/rss/rssfeed.cpp | 47 +++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/rss/rssarticle.cpp b/src/rss/rssarticle.cpp index c4636be63..50933d8f2 100644 --- a/src/rss/rssarticle.cpp +++ b/src/rss/rssarticle.cpp @@ -221,28 +221,29 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml) QDateTime date; QString author; - Q_ASSERT(xml.isStartElement() && xml.name() == "item"); + while(!xml.atEnd()) { + xml.readNext(); - while (xml.readNextStartElement()) { - if (xml.name() == "title") - title = xml.readElementText(); - else if (xml.name() == "enclosure") { - if (xml.attributes().value("type") == "application/x-bittorrent") - torrentUrl = xml.attributes().value("url").toString(); - } - else if (xml.name() == "link") - link = xml.readElementText(); - else if (xml.name() == "description") - description = xml.readElementText(); - else if (xml.name() == "pubDate") - date = RssArticle::parseDate(xml.readElementText()); - else if (xml.name() == "author") - author = xml.readElementText(); - else if (xml.name() == "guid") - guid = xml.readElementText(); - else { - qDebug() << "Skipping item tag: " << xml.name(); - xml.skipCurrentElement(); + if(xml.isEndElement() && xml.name() == "item") + break; + + if (xml.isStartElement()) { + if (xml.name() == "title") + title = xml.readElementText(); + else if (xml.name() == "enclosure") { + if (xml.attributes().value("type") == "application/x-bittorrent") + torrentUrl = xml.attributes().value("url").toString(); + } + else if (xml.name() == "link") + link = xml.readElementText(); + else if (xml.name() == "description") + description = xml.readElementText(); + else if (xml.name() == "pubDate") + date = RssArticle::parseDate(xml.readElementText()); + else if (xml.name() == "author") + author = xml.readElementText(); + else if (xml.name() == "guid") + guid = xml.readElementText(); } } diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index d0aac714c..cdd7ade8b 100644 --- a/src/rss/rssfeed.cpp +++ b/src/rss/rssfeed.cpp @@ -214,31 +214,32 @@ void RssFeed::parseRSSChannel(QXmlStreamReader& xml) qDebug() << Q_FUNC_INFO; Q_ASSERT(xml.isStartElement() && xml.name() == "channel"); - while (xml.readNextStartElement()) { - if (xml.name() == "title") { - m_title = xml.readElementText(); - if (m_alias == url()) - rename(m_title); - } - else if (xml.name() == "image") { - QString icon_path = xml.attributes().value("url").toString(); - if (!icon_path.isEmpty()) { - m_iconUrl = icon_path; - m_manager->rssDownloader()->downloadUrl(m_iconUrl); + while(!xml.atEnd()) { + xml.readNext(); + + if (xml.isStartElement()) { + if (xml.name() == "title") { + m_title = xml.readElementText(); + if (m_alias == url()) + rename(m_title); } - } - else if (xml.name() == "item") { - RssArticlePtr article = xmlToRssArticle(this, xml); - qDebug() << "Found RSS Item, valid: " << (article ? "True" : "False"); - if (article) { - QString guid = article->guid(); - if (m_articles.contains(guid) && m_articles[guid]->isRead()) - article->markAsRead(); - m_articles[guid] = article; + else if (xml.name() == "image") { + QString icon_path = xml.attributes().value("url").toString(); + if (!icon_path.isEmpty()) { + m_iconUrl = icon_path; + m_manager->rssDownloader()->downloadUrl(m_iconUrl); + } + } + else if (xml.name() == "item") { + RssArticlePtr article = xmlToRssArticle(this, xml); + qDebug() << "Found RSS Item, valid: " << (article ? "True" : "False"); + if (article) { + QString guid = article->guid(); + if (m_articles.contains(guid) && m_articles[guid]->isRead()) + article->markAsRead(); + m_articles[guid] = article; + } } - } else { - qDebug() << "Skipping RSS tag: " << xml.name(); - xml.skipCurrentElement(); } } }