Xml parsing : XML error: "Premature end of document."



  • unable to parse XML.
    http://api.discogs.com/release/4599294?f=xml (xml link )

    i want to read all node 1 by 1

    @void DiscogsApi::RequestApiSecond(QString url1)
    {

    QUrl url("http://api.discogs.com/release/4599294?f=xml");
    QNetworkRequest requestTagAndData;
    requestTagAndData.setUrl(QUrl(url));
    QNetworkAccessManager *managerDiscogsSecondApi = new QNetworkAccessManager(this);
    downloadreplyTagAndData = managerDiscogsSecondApi->get(requestTagAndData);
    
    connect(downloadreplyTagAndData,SIGNAL(readyRead()),this,SLOT(onReadyReadSecondApi()));
    connect(downloadreplyTagAndData,SIGNAL(finished()),this,SLOT(onReplyFinishedSecondApi(QNetworkReply*)));
    connect(managerDiscogsSecondApi,SIGNAL(finished(QNetworkReply*)),this,SLOT(slot_parse_search_response_SecondApi(QNetworkReply*)));
    

    }@
    @void DiscogsApi::onReadyReadSecondApi()
    {

    }
    void DiscogsApi::onReplyFinishedSecondApi(QNetworkReply * reply)
    {

    QTemporaryFile temp_file;
    temp_file.write(reply->readAll());
    

    }
    void DiscogsApi::slot_parse_search_response_SecondApi(QNetworkReply *replyy)
    {
    qDebug()<<replyy->readAll();
    QXmlStreamReader xml(replyy->readAll());
    // xml.addData(replyy->readAll());
    while( !xml.atEnd() && !xml.hasError() )
    {
    qDebug()<<"1";
    xml.readNext();
    if(xml.name() == "release" )
    {
    qDebug()<<"2";
    }
    }
    if (xml.hasError())
    {
    qDebug() << "XML error: " << xml.errorString() ;
    }
    else if (xml.atEnd())
    {
    qDebug()<< "Reached end, done" ;
    }
    }@


  • Lifetime Qt Champion

    Hi,

    You are calling readAll several times which won't have the result you expect. AFAIK, the first read will put file position to its end, the other will try read from that point.

    Also you're doing it from several different points, which isn't good design.

    You'd better redo your logic

    Hope it helps


Log in to reply
 

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