PDA

View Full Version : XML read problem



Archa4
7th February 2011, 09:29
I encountered a strange thing while trying to read xml. I used code that almost anyone used to parse XML. The thing is - i cannot get mine program to read the full XML at once. Instead it reads the page dividing it into parts, and each time it reads the html - it divides it into different parts. Is there anyway to make the program read the xml after it got all the data?

two of many functions I used:
void List::readData(const QHttpResponseHeader &resp)

void List::readData(const QHttpResponseHeader &resp)
{
if (resp.statusCode() != 200)
http.abort();
else
{
xml.addData(http.readAll());
parseXml();
}
}

void List::finished(int id, bool error)
{
if (error)
{
QMessageBox::warning(this, "Error", http.errorString());

}
else if (id == connectionId)
{

}
}

Tomasz
7th February 2011, 11:00
QHttp class reference says:

"This class provides a direct interface to HTTP that allows you to download and upload data with the HTTP protocol. However, for new applications, it is recommended to use QNetworkAccessManager and QNetworkReply, as those classes possess a simpler, yet more powerful API and a more modern protocol implementation."

Maybe You should Use QNetworkAccessManager and QNetworkReply? I use It to download XML file, and it works well (only in one case I have problems with it).



void MainWindow::getXML()
{
QNetworkRequest request(QUrl("http://something.com"));
NetRepl = NetAccMan.get(request);
connect(NetRepl, SIGNAL(readyRead()), this, SLOT(parseXML()));
}

void MainWindow::parseXML()
{
//parse Your XML
}

best regards
Tomasz

Archa4
7th February 2011, 11:12
Thanks, I'll look into QNetAccMan...
I solved mine problem moving the parseXml into finished function...