PDA

View Full Version : RSS, problem reading XML.



Archa4
4th February 2011, 10:41
I need to read an XML file in order to accomplish my task. I can read it using the example i found in mine Nokia QT SDK. But if i try to modify it a little bit - it doesn't work. Here is the parseXml function i have:
void List:: parseXml()


{
int a = 0;
while (!xml.atEnd())
{
xml.readNext();
if (xml.isStartElement())
{
currentTag = xml.name().toString();
}
else if (xml.isEndElement())
{
if (xml.name() == "movie")
{

listWidget->insertItem(a, "");
listWidget->setItemWidget(listWidget->item(a), new Custom_Widget(titleString, dateString, aboutString, pictureString));
listWidget->item(a)->setSizeHint(QSize (350,470));
listWidget->setSpacing(1);
titleString.clear();
dateString.clear();
aboutString.clear();
pictureString.clear();
a = a + 1;
}

}
else if (xml.isCharacters() && !xml.isWhitespace())
{
if (currentTag == "title")
titleString += xml.text().toString();
else if (currentTag == "globalReleaseDate")
dateString += xml.text().toString();
else if (currentTag == "annotation")
aboutString += xml.text().toString();
else if (currentTag == "imageType1")
pictureString += xml.text().toString();
}
}
if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError)
{
qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString();
http.abort();
}
}


This code works on this page:
http://www.forumcinemas.lv/rss/xml/movies/

But now i want to make it work on other pages (the ones that usually contain items not movies). I tried to adjust this function to define the type of XML by the first tag in the file (here i was trying to make function to find tag "movieList". Unfortunately, the function does not complete the task. It finds only 2 movies (of 20) and then stops. Could someone please advice, how to change this function, so that it would work as i want (whole function works only if it finds the "movieList" tag).