Results 1 to 4 of 4

Thread: Error while reading an XML

  1. #1
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Error while reading an XML

    i have already made an xml.
    but when i m reading it it shows error while setiing in device.

    my code is:--

    void XMLReader::read(QString fileName) //// file name is the xml name
    {
    QFile xmlFile(fileName);
    xmlFile.open(QIODevice::ReadOnly);

    qDebug()<<"///////////////////////////"<<xmlFile.isOpen(); ------>> shows its open

    xml.setDevice(&xmlFile); ----->> shows error here

    if (xml.readNextStartElement() && xml.name() == "Summary")
    processSummary();

    if (xml.tokenType() == QXmlStreamReader::Invalid)
    xml.readNext();

    if (xml.hasError()) {
    xml.raiseError();
    qDebug() << "error" << endl;
    }



    }

    void XMLReader:rocessSummary()
    {
    if(!xml.isStartElement() || xml.name()!= "Summary")
    return;


    QString blankspaces;
    QString blanklines;
    QString words;
    QString with_hash;

    while (xml.readNextStartElement()) {
    if (xml.name() == "no_of_blank_spaces")
    blankspaces=xml.text().toString();
    if (xml.name() == "no_of_blank_lines")
    blanklines=xml.text().toString();
    if (xml.name() == "no_of_words")
    words=xml.text().toString();
    if (xml.name() == "no_of_lines_starting_with_hash")
    with_hash= xml.text().toString();

    }
    qDebug()<<"please answer" <<blankspaces << endl;

    }

    my XML is---


    <?xml version="1.0" encoding="UTF-8"?>
    <Summary>
    <no_of_blank_spaces>13</no_of_blank_spaces>
    <no_of_blank_lines>8</no_of_blank_lines>
    <no_of_words>16</no_of_words>
    <no_of_lines_starting_with_hash>2</no_of_lines_starting_with_hash>
    </Summary>




    it shos the output ""error""..


    please help

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error while reading an XML

    What is the error you get ???

  3. #3
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error while reading an XML

    i get the output as ERROR from this code--

    if (xml.hasError()) {
    xml.raiseError();
    qDebug() << "error" << endl;
    }

  4. #4
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error while reading an XML

    I am not able to set content in qdomdocument.

Similar Threads

  1. Error in reading wav-file header
    By davidlamhauge in forum Qt Programming
    Replies: 5
    Last Post: 18th November 2012, 14:35
  2. Reading standard error from a process
    By harden in forum Newbie
    Replies: 6
    Last Post: 26th July 2011, 16:14
  3. unknown error reading svg file
    By RickF in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2010, 02:12
  4. Fatal IO error with QGLWidget and reading a file
    By mcn in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2010, 15:21
  5. QextSerialPort reading error: wrong values
    By Lawand in forum Qt Programming
    Replies: 9
    Last Post: 6th May 2009, 19:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.