PDA

View Full Version : Error while reading an XML



abhi8888
11th June 2015, 10:46
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::processSummary()
{
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

aamer4yu
11th June 2015, 11:47
What is the error you get ???

abhi8888
12th June 2015, 07:50
i get the output as ERROR from this code--

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

abhi8888
12th June 2015, 10:00
I am not able to set content in qdomdocument.