PDA

View Full Version : Error while setting content in dom reader



abhi8888
12th June 2015, 10:18
Hey.. i am a newbie.. so please be patient..
using xml and qt for first time.


i am trying to read a xml using a dom reader, but it shows a error---

MY XML---


<?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>



MY DOM READER CODE---




void DOMReader::parseFile(QString fileName) {

QFile file(fileName);

//file.open(QIODevice::ReadOnly);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "Not able to open the file";
return;
}

qDebug()<<"///////////////////////////"<<file.isOpen();----> IT SHOWS OPEN here.

QString errMsg;
int errLine;
int errCol;


QDomDocument doc;


if (!doc.setContent(&file,false,&errMsg,&errLine,&errCol)) {
qDebug() << "errMsg : " << errMsg;
qDebug() << "errLine : " << errLine;
qDebug() << "errCol : " << errCol;

qDebug() << "Error in XML File format" <<endl;
return;
}
QDomElement root = doc.documentElement();
if (root.tagName() != "Summary") {
qDebug() << "Error in root" << endl;
return;
}
processRoot(root);
return;
}

void DOMReader::processRoot(QDomElement root)
{
qDebug()<< "***********in dom*********" << endl;
}




I am getting a error as--:

errorMSg:-"unexpected end of file"
errLINe:1
errCol:1
Error in XML Format..




kindly help me through..

ChrisW67
12th June 2015, 13:28
Your code, test file, and your error message do not match. Please copy and paste rather than retyping. Also, put your code between
... tags

With your test file as posted:


<?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>

your code generates:


/////////////////////////// true
errMsg : "error occurred while parsing element"
errLine : 3
errCol : 1
Error in XML File format

and it is the direct result of the 3rd line starting with a hyphen.