Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Xml parsing : XML error: "Premature end of document."
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vivekmalik2466
    wrote on 18 Jun 2013, 11:21 last edited by
    #1

    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" ;
    }
    }@

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Jun 2013, 12:22 last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      18 Jun 2013, 11:21

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved